Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
c203f682
Commit
c203f682
authored
Jul 12, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add capitalize example
parent
a73ed78f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
capitalize.cpp
example/capitalize/capitalize.cpp
+61
-0
No files found.
example/capitalize/capitalize.cpp
0 → 100644
View file @
c203f682
// JSON condenser exmaple
// This example parses JSON from stdin with validation,
// and re-output the JSON content to stdout with all string capitalized, and without whitespace.
#include "rapidjson/reader.h"
#include "rapidjson/writer.h"
#include "rapidjson/filereadstream.h"
#include "rapidjson/filewritestream.h"
#include "rapidjson/error/en.h"
#include <vector>
#include <cctype>
using
namespace
rapidjson
;
template
<
typename
OutputHandler
>
struct
CapitalizeFilter
{
CapitalizeFilter
(
OutputHandler
&
out
)
:
out_
(
out
),
buffer_
()
{}
bool
Null
()
{
return
out_
.
Null
();
}
bool
Bool
(
bool
b
)
{
return
out_
.
Bool
(
b
);
}
bool
Int
(
int
i
)
{
return
out_
.
Int
(
i
);
}
bool
Uint
(
unsigned
u
)
{
return
out_
.
Uint
(
u
);
}
bool
Int64
(
int64_t
i
)
{
return
out_
.
Int64
(
i
);
}
bool
Uint64
(
uint64_t
u
)
{
return
out_
.
Uint64
(
u
);
}
bool
Double
(
double
d
)
{
return
out_
.
Double
(
d
);
}
bool
String
(
const
char
*
str
,
SizeType
length
,
bool
)
{
buffer_
.
clear
();
for
(
SizeType
i
=
0
;
i
<
length
;
i
++
)
buffer_
.
push_back
(
std
::
toupper
(
str
[
i
]));
return
out_
.
String
(
&
buffer_
.
front
(),
length
,
true
);
// true = output handler need to copy the string
}
bool
StartObject
()
{
return
out_
.
StartObject
();
}
bool
EndObject
(
SizeType
memberCount
)
{
return
out_
.
EndObject
(
memberCount
);
}
bool
StartArray
()
{
return
out_
.
StartArray
();
}
bool
EndArray
(
SizeType
elementCount
)
{
return
out_
.
EndArray
(
elementCount
);
}
OutputHandler
&
out_
;
std
::
vector
<
char
>
buffer_
;
};
int
main
(
int
,
char
*
[])
{
// Prepare JSON reader and input stream.
Reader
reader
;
char
readBuffer
[
65536
];
FileReadStream
is
(
stdin
,
readBuffer
,
sizeof
(
readBuffer
));
// Prepare JSON writer and output stream.
char
writeBuffer
[
65536
];
FileWriteStream
os
(
stdout
,
writeBuffer
,
sizeof
(
writeBuffer
));
Writer
<
FileWriteStream
>
writer
(
os
);
// JSON reader parse from the input stream and let writer generate the output.
CapitalizeFilter
<
Writer
<
FileWriteStream
>
>
filter
(
writer
);
if
(
!
reader
.
Parse
(
is
,
filter
))
{
fprintf
(
stderr
,
"
\n
Error(%u): %s
\n
"
,
(
unsigned
)
reader
.
GetErrorOffset
(),
GetParseError_En
(
reader
.
GetParseErrorCode
()));
return
1
;
}
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment