diff options
author | Vasily Gerasimov <UgnineSirdis@gmail.com> | 2022-02-10 16:49:09 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:09 +0300 |
commit | 6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (patch) | |
tree | f69637041e6fed76ebae0c74ae1fa0c4be6ab5b4 /library/cpp/json/writer | |
parent | e5d4696304c6689379ac7ce334512404d4b7836c (diff) | |
download | ydb-6cdc8f140213c595e4ad38bc3d97fcef1146b8c3.tar.gz |
Restoring authorship annotation for Vasily Gerasimov <UgnineSirdis@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/json/writer')
-rw-r--r-- | library/cpp/json/writer/json.cpp | 6 | ||||
-rw-r--r-- | library/cpp/json/writer/json.h | 20 | ||||
-rw-r--r-- | library/cpp/json/writer/json_ut.cpp | 78 |
3 files changed, 52 insertions, 52 deletions
diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index 02370c2d79..d4e5eaf6b3 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -258,16 +258,16 @@ namespace NJsonWriter { } else { ythrow TError() << "JSON writer: invalid float value: " << FloatToString(f); } - } + } size_t len = FloatToString(f, buf, Y_ARRAY_SIZE(buf), mode, ndigits); UnsafeWriteValue(buf, len); return TValueContext(*this); - } + } TValueContext TBuf::WriteFloat(float f, EFloatToStringMode mode, int ndigits) { return WriteFloatImpl(f, mode, ndigits); } - + TValueContext TBuf::WriteDouble(double f, EFloatToStringMode mode, int ndigits) { return WriteFloatImpl(f, mode, ndigits); } diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h index 0aae2531b9..57770fce8f 100644 --- a/library/cpp/json/writer/json.h +++ b/library/cpp/json/writer/json.h @@ -77,14 +77,14 @@ namespace NJsonWriter { return *this; } - /*** NaN and Inf are not valid json values, - * so if WriteNanAsString is set, writer would write string - * intead of throwing exception (default case) */ + /*** NaN and Inf are not valid json values, + * so if WriteNanAsString is set, writer would write string + * intead of throwing exception (default case) */ TBuf& SetWriteNanAsString(bool writeNanAsString = true) { - WriteNanAsString = writeNanAsString; + WriteNanAsString = writeNanAsString; return *this; - } - + } + /*** Return the string formed in the internal TStringStream. * You may only call it if the `stream' parameter was NULL * at construction time. */ @@ -141,10 +141,10 @@ namespace NJsonWriter { void CheckAndPop(EJsonEntity e); EJsonEntity StackTop() const; - template <class TFloat> - TValueContext WriteFloatImpl(TFloat f, EFloatToStringMode mode, int ndigits); + template <class TFloat> + TValueContext WriteFloatImpl(TFloat f, EFloatToStringMode mode, int ndigits); - private: + private: IOutputStream* Stream; THolder<TStringStream> StringStream; typedef TVector<const TString*> TKeys; @@ -155,7 +155,7 @@ namespace NJsonWriter { bool NeedNewline; const EHtmlEscapeMode EscapeMode; int IndentSpaces; - bool WriteNanAsString; + bool WriteNanAsString; }; // Please don't try to instantiate the classes declared below this point. diff --git a/library/cpp/json/writer/json_ut.cpp b/library/cpp/json/writer/json_ut.cpp index 9980555683..de6df4e941 100644 --- a/library/cpp/json/writer/json_ut.cpp +++ b/library/cpp/json/writer/json_ut.cpp @@ -4,8 +4,8 @@ #include "json.h" #include <library/cpp/json/json_value.h> -#include <limits> - +#include <limits> + Y_UNIT_TEST_SUITE(JsonWriter) { Y_UNIT_TEST(Struct) { NJsonWriter::TBuf w; @@ -205,53 +205,53 @@ Y_UNIT_TEST_SUITE(JsonWriter) { const char exp[] = "[0.123457,0.1234567899,0.316,244.1,10385.83,{\"1\":1112,\"2\":1e+03}]"; UNIT_ASSERT_STRINGS_EQUAL(exp, buf.Str()); } - + Y_UNIT_TEST(NanFormatting) { - { - NJsonWriter::TBuf buf; - buf.BeginObject(); - buf.WriteKey("nanvalue"); - UNIT_ASSERT_EXCEPTION(buf.WriteFloat(std::numeric_limits<double>::quiet_NaN()), yexception); - } - - { - NJsonWriter::TBuf buf; - buf.BeginObject(); - buf.WriteKey("infvalue"); - UNIT_ASSERT_EXCEPTION(buf.WriteFloat(std::numeric_limits<double>::infinity()), yexception); - } - - { - NJsonWriter::TBuf buf; - buf.BeginList(); - UNIT_ASSERT_EXCEPTION(buf.WriteFloat(std::numeric_limits<double>::quiet_NaN()), yexception); - } - - { - NJsonWriter::TBuf buf; - buf.BeginList(); - UNIT_ASSERT_EXCEPTION(buf.WriteFloat(std::numeric_limits<double>::infinity()), yexception); - } - - { - NJsonWriter::TBuf buf; - buf.SetWriteNanAsString(); - - buf.BeginObject() + { + NJsonWriter::TBuf buf; + buf.BeginObject(); + buf.WriteKey("nanvalue"); + UNIT_ASSERT_EXCEPTION(buf.WriteFloat(std::numeric_limits<double>::quiet_NaN()), yexception); + } + + { + NJsonWriter::TBuf buf; + buf.BeginObject(); + buf.WriteKey("infvalue"); + UNIT_ASSERT_EXCEPTION(buf.WriteFloat(std::numeric_limits<double>::infinity()), yexception); + } + + { + NJsonWriter::TBuf buf; + buf.BeginList(); + UNIT_ASSERT_EXCEPTION(buf.WriteFloat(std::numeric_limits<double>::quiet_NaN()), yexception); + } + + { + NJsonWriter::TBuf buf; + buf.BeginList(); + UNIT_ASSERT_EXCEPTION(buf.WriteFloat(std::numeric_limits<double>::infinity()), yexception); + } + + { + NJsonWriter::TBuf buf; + buf.SetWriteNanAsString(); + + buf.BeginObject() .WriteKey("nanvalue") .WriteFloat(std::numeric_limits<double>::quiet_NaN()) .WriteKey("infvalue") .WriteFloat(std::numeric_limits<double>::infinity()) .WriteKey("minus_infvalue") .WriteFloat(-std::numeric_limits<float>::infinity()) - .WriteKey("l") + .WriteKey("l") .BeginList() .WriteFloat(std::numeric_limits<float>::quiet_NaN()) .EndList() .EndObject(); - - UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"raw_json({"nanvalue":"nan","infvalue":"inf","minus_infvalue":"-inf","l":["nan"]})raw_json"); - } + + UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"raw_json({"nanvalue":"nan","infvalue":"inf","minus_infvalue":"-inf","l":["nan"]})raw_json"); + } { NJsonWriter::TBuf buf; @@ -264,7 +264,7 @@ Y_UNIT_TEST_SUITE(JsonWriter) { UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"({"\u003C\u003E&":"Ololo","<>&":"Ololo2"})"); } - } + } Y_UNIT_TEST(WriteUninitializedBoolDoesntCrashProgram) { // makes sense only in release build w/ address sanitizer |