mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-10-15 15:16:47 +02:00
Added emitUTF8 setting. (#1045)
* Added emitUTF8 setting to emit UTF8 format JSON. * Added a test for emitUTF8, with it in default, on and off states. * Review comments addressed. * Merged master into my branch & resolved conflicts. * Fix clang-format errors. * Fix clang-format errors. * Fixed clang-format errors. * Fixed clang-format errors.
This commit is contained in:

committed by
Jordan Bayles

parent
f59ac2a1d7
commit
a955529e47
@@ -2481,6 +2481,35 @@ JSONTEST_FIXTURE_LOCAL(StreamWriterTest, writeZeroes) {
|
||||
}
|
||||
}
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(StreamWriterTest, unicode) {
|
||||
// Create a Json value containing UTF-8 string with some chars that need
|
||||
// escape (tab,newline).
|
||||
Json::Value root;
|
||||
root["test"] = "\t\n\xF0\x91\xA2\xA1\x3D\xC4\xB3\xF0\x9B\x84\x9B\xEF\xBD\xA7";
|
||||
|
||||
Json::StreamWriterBuilder b;
|
||||
|
||||
// Default settings - should be unicode escaped.
|
||||
JSONTEST_ASSERT(Json::writeString(b, root) ==
|
||||
"{\n\t\"test\" : "
|
||||
"\"\\t\\n\\ud806\\udca1=\\u0133\\ud82c\\udd1b\\uff67\"\n}");
|
||||
|
||||
b.settings_["emitUTF8"] = true;
|
||||
|
||||
// Should not be unicode escaped.
|
||||
JSONTEST_ASSERT(
|
||||
Json::writeString(b, root) ==
|
||||
"{\n\t\"test\" : "
|
||||
"\"\\t\\n\xF0\x91\xA2\xA1=\xC4\xB3\xF0\x9B\x84\x9B\xEF\xBD\xA7\"\n}");
|
||||
|
||||
b.settings_["emitUTF8"] = false;
|
||||
|
||||
// Should be unicode escaped.
|
||||
JSONTEST_ASSERT(Json::writeString(b, root) ==
|
||||
"{\n\t\"test\" : "
|
||||
"\"\\t\\n\\ud806\\udca1=\\u0133\\ud82c\\udd1b\\uff67\"\n}");
|
||||
}
|
||||
|
||||
struct ReaderTest : JsonTest::TestCase {};
|
||||
|
||||
JSONTEST_FIXTURE_LOCAL(ReaderTest, parseWithNoErrors) {
|
||||
|
Reference in New Issue
Block a user