diff options
| author | Vasily Gerasimov <[email protected]> | 2022-02-10 16:49:10 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:49:10 +0300 | 
| commit | 1eb755fbca92172a6aec2f57371b2b3a19dfab43 (patch) | |
| tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/json | |
| parent | 6cdc8f140213c595e4ad38bc3d97fcef1146b8c3 (diff) | |
Restoring authorship annotation for Vasily Gerasimov <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/json')
| -rw-r--r-- | library/cpp/json/json_writer.h | 6 | ||||
| -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 | 
4 files changed, 55 insertions, 55 deletions
diff --git a/library/cpp/json/json_writer.h b/library/cpp/json/json_writer.h index 5da559ac359..c7f5c9499a4 100644 --- a/library/cpp/json/json_writer.h +++ b/library/cpp/json/json_writer.h @@ -5,7 +5,7 @@  #include "json_value.h"  #include <library/cpp/json/writer/json.h> -  +  #include <util/stream/output.h>  #include <util/generic/hash.h>  #include <util/generic/maybe.h> @@ -133,7 +133,7 @@ namespace NJson {              Buf.WriteKey(key);              Write(value);          } -  +          // write raw json without checks          void UnsafeWrite(const TStringBuf& key, const TStringBuf& value) {              Buf.WriteKey(key); @@ -144,7 +144,7 @@ namespace NJson {              Buf.WriteKey(key);              WriteNull();          } -  +          template <typename T>          void WriteOptional(const TStringBuf& key, const TMaybe<T>& value) {              if (value) { diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index d4e5eaf6b35..02370c2d79e 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 57770fce8f8..0aae2531b94 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 de6df4e941f..9980555683f 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  | 
