Skip to content

Commit a627774

Browse files
committed
Normalize line endings but not JSON files
1 parent 7fb84d3 commit a627774

36 files changed

+8276
-8276
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*.h text
88
*.txt text
99
*.md text
10-
*.json text
1110
*.cmake text
1211
*.svg text
1312
*.dot text
@@ -20,3 +19,4 @@ Dockerfile text
2019
# Denote all files that are truly binary and should not be modified.
2120
*.png binary
2221
*.jpg binary
22+
*.json binary

bin/data/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sample.json is obtained from http://code.google.com/p/json-test-suite/downloads/detail?name=sample.zip
1+
sample.json is obtained from http://code.google.com/p/json-test-suite/downloads/detail?name=sample.zip

example/condense/condense.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
// JSON condenser example
2-
3-
// This example parses JSON text from stdin with validation,
4-
// and re-output the JSON content to stdout without whitespace.
5-
6-
#include "rapidjson/reader.h"
7-
#include "rapidjson/writer.h"
8-
#include "rapidjson/filereadstream.h"
9-
#include "rapidjson/filewritestream.h"
10-
#include "rapidjson/error/en.h"
11-
12-
using namespace rapidjson;
13-
14-
int main(int, char*[]) {
15-
// Prepare JSON reader and input stream.
16-
Reader reader;
17-
char readBuffer[65536];
18-
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
19-
20-
// Prepare JSON writer and output stream.
21-
char writeBuffer[65536];
22-
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
23-
Writer<FileWriteStream> writer(os);
24-
25-
// JSON reader parse from the input stream and let writer generate the output.
26-
if (!reader.Parse(is, writer)) {
27-
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
28-
return 1;
29-
}
30-
31-
return 0;
32-
}
1+
// JSON condenser example
2+
3+
// This example parses JSON text from stdin with validation,
4+
// and re-output the JSON content to stdout without whitespace.
5+
6+
#include "rapidjson/reader.h"
7+
#include "rapidjson/writer.h"
8+
#include "rapidjson/filereadstream.h"
9+
#include "rapidjson/filewritestream.h"
10+
#include "rapidjson/error/en.h"
11+
12+
using namespace rapidjson;
13+
14+
int main(int, char*[]) {
15+
// Prepare JSON reader and input stream.
16+
Reader reader;
17+
char readBuffer[65536];
18+
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
19+
20+
// Prepare JSON writer and output stream.
21+
char writeBuffer[65536];
22+
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
23+
Writer<FileWriteStream> writer(os);
24+
25+
// JSON reader parse from the input stream and let writer generate the output.
26+
if (!reader.Parse(is, writer)) {
27+
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
28+
return 1;
29+
}
30+
31+
return 0;
32+
}

example/pretty/pretty.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
// JSON pretty formatting example
2-
// This example can only handle UTF-8. For handling other encodings, see prettyauto example.
3-
4-
#include "rapidjson/reader.h"
5-
#include "rapidjson/prettywriter.h"
6-
#include "rapidjson/filereadstream.h"
7-
#include "rapidjson/filewritestream.h"
8-
#include "rapidjson/error/en.h"
9-
10-
using namespace rapidjson;
11-
12-
int main(int, char*[]) {
13-
// Prepare reader and input stream.
14-
Reader reader;
15-
char readBuffer[65536];
16-
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
17-
18-
// Prepare writer and output stream.
19-
char writeBuffer[65536];
20-
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
21-
PrettyWriter<FileWriteStream> writer(os);
22-
23-
// JSON reader parse from the input stream and let writer generate the output.
24-
if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) {
25-
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
26-
return 1;
27-
}
28-
29-
return 0;
30-
}
1+
// JSON pretty formatting example
2+
// This example can only handle UTF-8. For handling other encodings, see prettyauto example.
3+
4+
#include "rapidjson/reader.h"
5+
#include "rapidjson/prettywriter.h"
6+
#include "rapidjson/filereadstream.h"
7+
#include "rapidjson/filewritestream.h"
8+
#include "rapidjson/error/en.h"
9+
10+
using namespace rapidjson;
11+
12+
int main(int, char*[]) {
13+
// Prepare reader and input stream.
14+
Reader reader;
15+
char readBuffer[65536];
16+
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
17+
18+
// Prepare writer and output stream.
19+
char writeBuffer[65536];
20+
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
21+
PrettyWriter<FileWriteStream> writer(os);
22+
23+
// JSON reader parse from the input stream and let writer generate the output.
24+
if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) {
25+
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
26+
return 1;
27+
}
28+
29+
return 0;
30+
}

example/prettyauto/prettyauto.cpp

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
// JSON pretty formatting example
2-
// This example can handle UTF-8/UTF-16LE/UTF-16BE/UTF-32LE/UTF-32BE.
3-
// The input firstly convert to UTF8, and then write to the original encoding with pretty formatting.
4-
5-
#include "rapidjson/reader.h"
6-
#include "rapidjson/prettywriter.h"
7-
#include "rapidjson/filereadstream.h"
8-
#include "rapidjson/filewritestream.h"
9-
#include "rapidjson/encodedstream.h" // NEW
10-
#include "rapidjson/error/en.h"
11-
#ifdef _WIN32
12-
#include <fcntl.h>
13-
#include <io.h>
14-
#endif
15-
16-
using namespace rapidjson;
17-
18-
int main(int, char*[]) {
19-
#ifdef _WIN32
20-
// Prevent Windows converting between CR+LF and LF
21-
_setmode(_fileno(stdin), _O_BINARY); // NEW
22-
_setmode(_fileno(stdout), _O_BINARY); // NEW
23-
#endif
24-
25-
// Prepare reader and input stream.
26-
//Reader reader;
27-
GenericReader<AutoUTF<unsigned>, UTF8<> > reader; // CHANGED
28-
char readBuffer[65536];
29-
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
30-
AutoUTFInputStream<unsigned, FileReadStream> eis(is); // NEW
31-
32-
// Prepare writer and output stream.
33-
char writeBuffer[65536];
34-
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
35-
36-
#if 1
37-
// Use the same Encoding of the input. Also use BOM according to input.
38-
typedef AutoUTFOutputStream<unsigned, FileWriteStream> OutputStream; // NEW
39-
OutputStream eos(os, eis.GetType(), eis.HasBOM()); // NEW
40-
PrettyWriter<OutputStream, UTF8<>, AutoUTF<unsigned> > writer(eos); // CHANGED
41-
#else
42-
// You may also use static bound encoding type, such as output to UTF-16LE with BOM
43-
typedef EncodedOutputStream<UTF16LE<>,FileWriteStream> OutputStream; // NEW
44-
OutputStream eos(os, true); // NEW
45-
PrettyWriter<OutputStream, UTF8<>, UTF16LE<> > writer(eos); // CHANGED
46-
#endif
47-
48-
// JSON reader parse from the input stream and let writer generate the output.
49-
//if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) {
50-
if (!reader.Parse<kParseValidateEncodingFlag>(eis, writer)) { // CHANGED
51-
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
52-
return 1;
53-
}
54-
55-
return 0;
56-
}
1+
// JSON pretty formatting example
2+
// This example can handle UTF-8/UTF-16LE/UTF-16BE/UTF-32LE/UTF-32BE.
3+
// The input firstly convert to UTF8, and then write to the original encoding with pretty formatting.
4+
5+
#include "rapidjson/reader.h"
6+
#include "rapidjson/prettywriter.h"
7+
#include "rapidjson/filereadstream.h"
8+
#include "rapidjson/filewritestream.h"
9+
#include "rapidjson/encodedstream.h" // NEW
10+
#include "rapidjson/error/en.h"
11+
#ifdef _WIN32
12+
#include <fcntl.h>
13+
#include <io.h>
14+
#endif
15+
16+
using namespace rapidjson;
17+
18+
int main(int, char*[]) {
19+
#ifdef _WIN32
20+
// Prevent Windows converting between CR+LF and LF
21+
_setmode(_fileno(stdin), _O_BINARY); // NEW
22+
_setmode(_fileno(stdout), _O_BINARY); // NEW
23+
#endif
24+
25+
// Prepare reader and input stream.
26+
//Reader reader;
27+
GenericReader<AutoUTF<unsigned>, UTF8<> > reader; // CHANGED
28+
char readBuffer[65536];
29+
FileReadStream is(stdin, readBuffer, sizeof(readBuffer));
30+
AutoUTFInputStream<unsigned, FileReadStream> eis(is); // NEW
31+
32+
// Prepare writer and output stream.
33+
char writeBuffer[65536];
34+
FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer));
35+
36+
#if 1
37+
// Use the same Encoding of the input. Also use BOM according to input.
38+
typedef AutoUTFOutputStream<unsigned, FileWriteStream> OutputStream; // NEW
39+
OutputStream eos(os, eis.GetType(), eis.HasBOM()); // NEW
40+
PrettyWriter<OutputStream, UTF8<>, AutoUTF<unsigned> > writer(eos); // CHANGED
41+
#else
42+
// You may also use static bound encoding type, such as output to UTF-16LE with BOM
43+
typedef EncodedOutputStream<UTF16LE<>,FileWriteStream> OutputStream; // NEW
44+
OutputStream eos(os, true); // NEW
45+
PrettyWriter<OutputStream, UTF8<>, UTF16LE<> > writer(eos); // CHANGED
46+
#endif
47+
48+
// JSON reader parse from the input stream and let writer generate the output.
49+
//if (!reader.Parse<kParseValidateEncodingFlag>(is, writer)) {
50+
if (!reader.Parse<kParseValidateEncodingFlag>(eis, writer)) { // CHANGED
51+
fprintf(stderr, "\nError(%u): %s\n", static_cast<unsigned>(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode()));
52+
return 1;
53+
}
54+
55+
return 0;
56+
}

0 commit comments

Comments
 (0)