aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/json
diff options
context:
space:
mode:
authorsvshevtsov <svshevtsov@yandex-team.ru>2022-02-10 16:49:37 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:37 +0300
commit657337012a264721d58c470b4e9e796611f3c492 (patch)
tree82753fd92cf7cc2dea4e522a945ed570131f920b /library/cpp/json
parent44f31b316af517a4fbc6a82ebed8a1c51807deac (diff)
downloadydb-657337012a264721d58c470b4e9e796611f3c492.tar.gz
Restoring authorship annotation for <svshevtsov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/json')
-rw-r--r--library/cpp/json/json_writer.cpp18
-rw-r--r--library/cpp/json/json_writer.h20
-rw-r--r--library/cpp/json/ut/json_writer_ut.cpp74
-rw-r--r--library/cpp/json/writer/json.cpp10
-rw-r--r--library/cpp/json/writer/json.h2
5 files changed, 62 insertions, 62 deletions
diff --git a/library/cpp/json/json_writer.cpp b/library/cpp/json/json_writer.cpp
index 3d058bae36..4f04c12a87 100644
--- a/library/cpp/json/json_writer.cpp
+++ b/library/cpp/json/json_writer.cpp
@@ -9,9 +9,9 @@ namespace NJson {
TJsonWriter::TJsonWriter(IOutputStream* out, bool formatOutput, bool sortkeys, bool validateUtf8)
: Out(out)
, Buf(NJsonWriter::HEM_UNSAFE)
- , DoubleNDigits(TJsonWriterConfig::DefaultDoubleNDigits)
- , FloatNDigits(TJsonWriterConfig::DefaultFloatNDigits)
- , FloatToStringMode(TJsonWriterConfig::DefaultFloatToStringMode)
+ , DoubleNDigits(TJsonWriterConfig::DefaultDoubleNDigits)
+ , FloatNDigits(TJsonWriterConfig::DefaultFloatNDigits)
+ , FloatToStringMode(TJsonWriterConfig::DefaultFloatToStringMode)
, SortKeys(sortkeys)
, ValidateUtf8(validateUtf8)
, DontEscapeStrings(false)
@@ -23,9 +23,9 @@ namespace NJson {
TJsonWriter::TJsonWriter(IOutputStream* out, const TJsonWriterConfig& config, bool DFID)
: Out(config.Unbuffered ? nullptr : out)
, Buf(NJsonWriter::HEM_UNSAFE, config.Unbuffered ? out : nullptr)
- , DoubleNDigits(config.DoubleNDigits)
- , FloatNDigits(config.FloatNDigits)
- , FloatToStringMode(config.FloatToStringMode)
+ , DoubleNDigits(config.DoubleNDigits)
+ , FloatNDigits(config.FloatNDigits)
+ , FloatToStringMode(config.FloatToStringMode)
, SortKeys(config.SortKeys)
, ValidateUtf8(config.ValidateUtf8)
, DontEscapeStrings(config.DontEscapeStrings)
@@ -87,11 +87,11 @@ namespace NJson {
}
void TJsonWriter::Write(float value) {
- Buf.WriteFloat(value, FloatToStringMode, FloatNDigits);
+ Buf.WriteFloat(value, FloatToStringMode, FloatNDigits);
}
void TJsonWriter::Write(double value) {
- Buf.WriteDouble(value, FloatToStringMode, DoubleNDigits);
+ Buf.WriteDouble(value, FloatToStringMode, DoubleNDigits);
}
void TJsonWriter::Write(long long value) {
@@ -115,7 +115,7 @@ namespace NJson {
}
void TJsonWriter::Write(const TJsonValue* v) {
- Buf.WriteJsonValue(v, SortKeys, FloatToStringMode, DoubleNDigits);
+ Buf.WriteJsonValue(v, SortKeys, FloatToStringMode, DoubleNDigits);
}
void TJsonWriter::Write(const TJsonValue& v) {
diff --git a/library/cpp/json/json_writer.h b/library/cpp/json/json_writer.h
index c7f5c9499a..729aaa939b 100644
--- a/library/cpp/json/json_writer.h
+++ b/library/cpp/json/json_writer.h
@@ -13,10 +13,10 @@
namespace NJson {
struct TJsonWriterConfig {
- constexpr static ui32 DefaultDoubleNDigits = 10;
- constexpr static ui32 DefaultFloatNDigits = 6;
- constexpr static EFloatToStringMode DefaultFloatToStringMode = PREC_NDIGITS;
-
+ constexpr static ui32 DefaultDoubleNDigits = 10;
+ constexpr static ui32 DefaultFloatNDigits = 6;
+ constexpr static EFloatToStringMode DefaultFloatToStringMode = PREC_NDIGITS;
+
inline TJsonWriterConfig& SetUnbuffered(bool v) noexcept {
Unbuffered = v;
@@ -35,9 +35,9 @@ namespace NJson {
return *this;
}
- ui32 DoubleNDigits = DefaultDoubleNDigits;
- ui32 FloatNDigits = DefaultFloatNDigits;
- EFloatToStringMode FloatToStringMode = DefaultFloatToStringMode;
+ ui32 DoubleNDigits = DefaultDoubleNDigits;
+ ui32 FloatNDigits = DefaultFloatNDigits;
+ EFloatToStringMode FloatToStringMode = DefaultFloatToStringMode;
bool FormatOutput = false;
bool SortKeys = false;
bool ValidateUtf8 = true;
@@ -49,9 +49,9 @@ namespace NJson {
class TJsonWriter {
IOutputStream* Out;
NJsonWriter::TBuf Buf;
- const ui32 DoubleNDigits;
- const ui32 FloatNDigits;
- const EFloatToStringMode FloatToStringMode;
+ const ui32 DoubleNDigits;
+ const ui32 FloatNDigits;
+ const EFloatToStringMode FloatToStringMode;
const bool SortKeys;
const bool ValidateUtf8;
const bool DontEscapeStrings;
diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp
index ca11d34dad..af38ccf662 100644
--- a/library/cpp/json/ut/json_writer_ut.cpp
+++ b/library/cpp/json/ut/json_writer_ut.cpp
@@ -187,42 +187,42 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) {
UNIT_ASSERT_VALUES_EQUAL(WrapJsonToCallback(json, ""), "\"A\"");
UNIT_ASSERT_VALUES_EQUAL(WrapJsonToCallback(json, "Foo"), "Foo(\"A\")");
}
-
+
Y_UNIT_TEST(FloatPrecision) {
- const double value = 1517933989.4242;
- const NJson::TJsonValue json(value);
- NJson::TJsonWriterConfig config;
- {
- TString expected = "1517933989";
- TString actual = NJson::WriteJson(json);
- UNIT_ASSERT_VALUES_EQUAL(actual, expected);
- }
- {
- TString expected = "1517933989";
-
- TStringStream ss;
- NJson::WriteJson(&ss, &json, config);
- TString actual = ss.Str();
- UNIT_ASSERT_VALUES_EQUAL(actual, expected);
- }
- {
- config.DoubleNDigits = 13;
- TString expected = "1517933989.424";
-
- TStringStream ss;
- NJson::WriteJson(&ss, &json, config);
- TString actual = ss.Str();
- UNIT_ASSERT_VALUES_EQUAL(actual, expected);
- }
- {
- config.DoubleNDigits = 6;
- config.FloatToStringMode = PREC_POINT_DIGITS;
- TString expected = "1517933989.424200";
-
- TStringStream ss;
- NJson::WriteJson(&ss, &json, config);
- TString actual = ss.Str();
- UNIT_ASSERT_VALUES_EQUAL(actual, expected);
- }
- }
+ const double value = 1517933989.4242;
+ const NJson::TJsonValue json(value);
+ NJson::TJsonWriterConfig config;
+ {
+ TString expected = "1517933989";
+ TString actual = NJson::WriteJson(json);
+ UNIT_ASSERT_VALUES_EQUAL(actual, expected);
+ }
+ {
+ TString expected = "1517933989";
+
+ TStringStream ss;
+ NJson::WriteJson(&ss, &json, config);
+ TString actual = ss.Str();
+ UNIT_ASSERT_VALUES_EQUAL(actual, expected);
+ }
+ {
+ config.DoubleNDigits = 13;
+ TString expected = "1517933989.424";
+
+ TStringStream ss;
+ NJson::WriteJson(&ss, &json, config);
+ TString actual = ss.Str();
+ UNIT_ASSERT_VALUES_EQUAL(actual, expected);
+ }
+ {
+ config.DoubleNDigits = 6;
+ config.FloatToStringMode = PREC_POINT_DIGITS;
+ TString expected = "1517933989.424200";
+
+ TStringStream ss;
+ NJson::WriteJson(&ss, &json, config);
+ TString actual = ss.Str();
+ UNIT_ASSERT_VALUES_EQUAL(actual, expected);
+ }
+ }
}
diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp
index 02370c2d79..1895ec2382 100644
--- a/library/cpp/json/writer/json.cpp
+++ b/library/cpp/json/writer/json.cpp
@@ -382,7 +382,7 @@ namespace NJsonWriter {
return *a < *b;
}
- TValueContext TBuf::WriteJsonValue(const NJson::TJsonValue* v, bool sortKeys, EFloatToStringMode mode, int ndigits) {
+ TValueContext TBuf::WriteJsonValue(const NJson::TJsonValue* v, bool sortKeys, EFloatToStringMode mode, int ndigits) {
using namespace NJson;
switch (v->GetType()) {
default:
@@ -393,7 +393,7 @@ namespace NJsonWriter {
WriteBool(v->GetBoolean());
break;
case JSON_DOUBLE:
- WriteDouble(v->GetDouble(), mode, ndigits);
+ WriteDouble(v->GetDouble(), mode, ndigits);
break;
case JSON_INTEGER:
WriteLongLong(v->GetInteger());
@@ -408,7 +408,7 @@ namespace NJsonWriter {
BeginList();
const TJsonValue::TArray& arr = v->GetArray();
for (const auto& it : arr)
- WriteJsonValue(&it, sortKeys, mode, ndigits);
+ WriteJsonValue(&it, sortKeys, mode, ndigits);
EndList();
break;
}
@@ -425,13 +425,13 @@ namespace NJsonWriter {
for (size_t i = oldsz, sz = Keys.size(); i < sz; ++i) {
TJsonValue::TMapType::const_iterator kv = map.find(*Keys[i]);
WriteKey(kv->first);
- WriteJsonValue(&kv->second, sortKeys, mode, ndigits);
+ WriteJsonValue(&kv->second, sortKeys, mode, ndigits);
}
Keys.resize(oldsz);
} else {
for (const auto& it : map) {
WriteKey(it.first);
- WriteJsonValue(&it.second, sortKeys, mode, ndigits);
+ WriteJsonValue(&it.second, sortKeys, mode, ndigits);
}
}
EndObject();
diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h
index 0aae2531b9..5f6d6c7d59 100644
--- a/library/cpp/json/writer/json.h
+++ b/library/cpp/json/writer/json.h
@@ -52,7 +52,7 @@ namespace NJsonWriter {
TValueContext WriteDouble(double f, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 10);
TValueContext WriteBool(bool b);
TValueContext WriteNull();
- TValueContext WriteJsonValue(const NJson::TJsonValue* value, bool sortKeys = false, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 10);
+ TValueContext WriteJsonValue(const NJson::TJsonValue* value, bool sortKeys = false, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 10);
TValueContext BeginList();
TBuf& EndList();