forked from Tencent/rapidjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize line endings but not JSON files
- Loading branch information
Showing
36 changed files
with
8,276 additions
and
8,276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
sample.json is obtained from http://code.google.com/p/json-test-suite/downloads/detail?name=sample.zip | ||
sample.json is obtained from http://code.google.com/p/json-test-suite/downloads/detail?name=sample.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
// JSON condenser example | ||
|
||
// This example parses JSON text from stdin with validation, | ||
// and re-output the JSON content to stdout without whitespace. | ||
|
||
#include "rapidjson/reader.h" | ||
#include "rapidjson/writer.h" | ||
#include "rapidjson/filereadstream.h" | ||
#include "rapidjson/filewritestream.h" | ||
#include "rapidjson/error/en.h" | ||
|
||
using namespace rapidjson; | ||
|
||
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. | ||
if (!reader.Parse(is, writer)) { | ||
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
// JSON condenser example | ||
|
||
// This example parses JSON text from stdin with validation, | ||
// and re-output the JSON content to stdout without whitespace. | ||
|
||
#include "rapidjson/reader.h" | ||
#include "rapidjson/writer.h" | ||
#include "rapidjson/filereadstream.h" | ||
#include "rapidjson/filewritestream.h" | ||
#include "rapidjson/error/en.h" | ||
|
||
using namespace rapidjson; | ||
|
||
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. | ||
if (!reader.Parse(is, writer)) { | ||
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
// JSON pretty formatting example | ||
// This example can only handle UTF-8. For handling other encodings, see prettyauto example. | ||
|
||
#include "rapidjson/reader.h" | ||
#include "rapidjson/prettywriter.h" | ||
#include "rapidjson/filereadstream.h" | ||
#include "rapidjson/filewritestream.h" | ||
#include "rapidjson/error/en.h" | ||
|
||
using namespace rapidjson; | ||
|
||
int main(int, char*[]) { | ||
// Prepare reader and input stream. | ||
Reader reader; | ||
char readBuffer[65536]; | ||
FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); | ||
|
||
// Prepare writer and output stream. | ||
char writeBuffer[65536]; | ||
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); | ||
PrettyWriter<FileWriteStream> writer(os); | ||
|
||
// JSON reader parse from the input stream and let writer generate the output. | ||
if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) { | ||
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
// JSON pretty formatting example | ||
// This example can only handle UTF-8. For handling other encodings, see prettyauto example. | ||
|
||
#include "rapidjson/reader.h" | ||
#include "rapidjson/prettywriter.h" | ||
#include "rapidjson/filereadstream.h" | ||
#include "rapidjson/filewritestream.h" | ||
#include "rapidjson/error/en.h" | ||
|
||
using namespace rapidjson; | ||
|
||
int main(int, char*[]) { | ||
// Prepare reader and input stream. | ||
Reader reader; | ||
char readBuffer[65536]; | ||
FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); | ||
|
||
// Prepare writer and output stream. | ||
char writeBuffer[65536]; | ||
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); | ||
PrettyWriter<FileWriteStream> writer(os); | ||
|
||
// JSON reader parse from the input stream and let writer generate the output. | ||
if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) { | ||
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
// JSON pretty formatting example | ||
// This example can handle UTF-8/UTF-16LE/UTF-16BE/UTF-32LE/UTF-32BE. | ||
// The input firstly convert to UTF8, and then write to the original encoding with pretty formatting. | ||
|
||
#include "rapidjson/reader.h" | ||
#include "rapidjson/prettywriter.h" | ||
#include "rapidjson/filereadstream.h" | ||
#include "rapidjson/filewritestream.h" | ||
#include "rapidjson/encodedstream.h" // NEW | ||
#include "rapidjson/error/en.h" | ||
#ifdef _WIN32 | ||
#include <fcntl.h> | ||
#include <io.h> | ||
#endif | ||
|
||
using namespace rapidjson; | ||
|
||
int main(int, char*[]) { | ||
#ifdef _WIN32 | ||
// Prevent Windows converting between CR+LF and LF | ||
_setmode(_fileno(stdin), _O_BINARY); // NEW | ||
_setmode(_fileno(stdout), _O_BINARY); // NEW | ||
#endif | ||
|
||
// Prepare reader and input stream. | ||
//Reader reader; | ||
GenericReader<AutoUTF<unsigned>, UTF8<> > reader; // CHANGED | ||
char readBuffer[65536]; | ||
FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); | ||
AutoUTFInputStream<unsigned, FileReadStream> eis(is); // NEW | ||
|
||
// Prepare writer and output stream. | ||
char writeBuffer[65536]; | ||
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); | ||
|
||
#if 1 | ||
// Use the same Encoding of the input. Also use BOM according to input. | ||
typedef AutoUTFOutputStream<unsigned, FileWriteStream> OutputStream; // NEW | ||
OutputStream eos(os, eis.GetType(), eis.HasBOM()); // NEW | ||
PrettyWriter<OutputStream, UTF8<>, AutoUTF<unsigned> > writer(eos); // CHANGED | ||
#else | ||
// You may also use static bound encoding type, such as output to UTF-16LE with BOM | ||
typedef EncodedOutputStream<UTF16LE<>,FileWriteStream> OutputStream; // NEW | ||
OutputStream eos(os, true); // NEW | ||
PrettyWriter<OutputStream, UTF8<>, UTF16LE<> > writer(eos); // CHANGED | ||
#endif | ||
|
||
// JSON reader parse from the input stream and let writer generate the output. | ||
//if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) { | ||
if (!reader.Parse<kParseValidateEncodingFlag>(eis, writer)) { // CHANGED | ||
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} | ||
// JSON pretty formatting example | ||
// This example can handle UTF-8/UTF-16LE/UTF-16BE/UTF-32LE/UTF-32BE. | ||
// The input firstly convert to UTF8, and then write to the original encoding with pretty formatting. | ||
|
||
#include "rapidjson/reader.h" | ||
#include "rapidjson/prettywriter.h" | ||
#include "rapidjson/filereadstream.h" | ||
#include "rapidjson/filewritestream.h" | ||
#include "rapidjson/encodedstream.h" // NEW | ||
#include "rapidjson/error/en.h" | ||
#ifdef _WIN32 | ||
#include <fcntl.h> | ||
#include <io.h> | ||
#endif | ||
|
||
using namespace rapidjson; | ||
|
||
int main(int, char*[]) { | ||
#ifdef _WIN32 | ||
// Prevent Windows converting between CR+LF and LF | ||
_setmode(_fileno(stdin), _O_BINARY); // NEW | ||
_setmode(_fileno(stdout), _O_BINARY); // NEW | ||
#endif | ||
|
||
// Prepare reader and input stream. | ||
//Reader reader; | ||
GenericReader<AutoUTF<unsigned>, UTF8<> > reader; // CHANGED | ||
char readBuffer[65536]; | ||
FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); | ||
AutoUTFInputStream<unsigned, FileReadStream> eis(is); // NEW | ||
|
||
// Prepare writer and output stream. | ||
char writeBuffer[65536]; | ||
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); | ||
|
||
#if 1 | ||
// Use the same Encoding of the input. Also use BOM according to input. | ||
typedef AutoUTFOutputStream<unsigned, FileWriteStream> OutputStream; // NEW | ||
OutputStream eos(os, eis.GetType(), eis.HasBOM()); // NEW | ||
PrettyWriter<OutputStream, UTF8<>, AutoUTF<unsigned> > writer(eos); // CHANGED | ||
#else | ||
// You may also use static bound encoding type, such as output to UTF-16LE with BOM | ||
typedef EncodedOutputStream<UTF16LE<>,FileWriteStream> OutputStream; // NEW | ||
OutputStream eos(os, true); // NEW | ||
PrettyWriter<OutputStream, UTF8<>, UTF16LE<> > writer(eos); // CHANGED | ||
#endif | ||
|
||
// JSON reader parse from the input stream and let writer generate the output. | ||
//if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) { | ||
if (!reader.Parse<kParseValidateEncodingFlag>(eis, writer)) { // CHANGED | ||
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.