aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/json/json_writer.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/json/json_writer.cpp
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/json/json_writer.cpp')
-rw-r--r--library/cpp/json/json_writer.cpp216
1 files changed, 108 insertions, 108 deletions
diff --git a/library/cpp/json/json_writer.cpp b/library/cpp/json/json_writer.cpp
index 140e1427d3..3d058bae36 100644
--- a/library/cpp/json/json_writer.cpp
+++ b/library/cpp/json/json_writer.cpp
@@ -6,144 +6,144 @@
#include <util/system/yassert.h>
namespace NJson {
- TJsonWriter::TJsonWriter(IOutputStream* out, bool formatOutput, bool sortkeys, bool validateUtf8)
- : Out(out)
- , Buf(NJsonWriter::HEM_UNSAFE)
+ 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)
- , SortKeys(sortkeys)
- , ValidateUtf8(validateUtf8)
- , DontEscapeStrings(false)
- , DontFlushInDestructor(false)
- {
- Buf.SetIndentSpaces(formatOutput ? 2 : 0);
- }
-
- TJsonWriter::TJsonWriter(IOutputStream* out, const TJsonWriterConfig& config, bool DFID)
- : Out(config.Unbuffered ? nullptr : out)
- , Buf(NJsonWriter::HEM_UNSAFE, config.Unbuffered ? out : nullptr)
+ , SortKeys(sortkeys)
+ , ValidateUtf8(validateUtf8)
+ , DontEscapeStrings(false)
+ , DontFlushInDestructor(false)
+ {
+ Buf.SetIndentSpaces(formatOutput ? 2 : 0);
+ }
+
+ 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)
- , SortKeys(config.SortKeys)
- , ValidateUtf8(config.ValidateUtf8)
- , DontEscapeStrings(config.DontEscapeStrings)
- , DontFlushInDestructor(DFID)
- {
- Buf.SetIndentSpaces(config.FormatOutput ? 2 : 0);
- Buf.SetWriteNanAsString(config.WriteNanAsString);
- }
-
- TJsonWriter::~TJsonWriter() {
- // if we write to socket it's possible to get exception here
- // don't use exceptions in destructors
- if (!DontFlushInDestructor) {
- try {
- Flush();
- } catch (...) {
- }
- }
- }
-
- void TJsonWriter::Flush() {
- if (Out) {
- Buf.FlushTo(Out);
+ , SortKeys(config.SortKeys)
+ , ValidateUtf8(config.ValidateUtf8)
+ , DontEscapeStrings(config.DontEscapeStrings)
+ , DontFlushInDestructor(DFID)
+ {
+ Buf.SetIndentSpaces(config.FormatOutput ? 2 : 0);
+ Buf.SetWriteNanAsString(config.WriteNanAsString);
+ }
+
+ TJsonWriter::~TJsonWriter() {
+ // if we write to socket it's possible to get exception here
+ // don't use exceptions in destructors
+ if (!DontFlushInDestructor) {
+ try {
+ Flush();
+ } catch (...) {
+ }
+ }
+ }
+
+ void TJsonWriter::Flush() {
+ if (Out) {
+ Buf.FlushTo(Out);
}
- }
+ }
- void TJsonWriter::OpenMap() {
- Buf.BeginObject();
- }
+ void TJsonWriter::OpenMap() {
+ Buf.BeginObject();
+ }
- void TJsonWriter::CloseMap() {
- Buf.EndObject();
- }
+ void TJsonWriter::CloseMap() {
+ Buf.EndObject();
+ }
- void TJsonWriter::OpenArray() {
- Buf.BeginList();
- }
+ void TJsonWriter::OpenArray() {
+ Buf.BeginList();
+ }
- void TJsonWriter::CloseArray() {
- Buf.EndList();
- }
+ void TJsonWriter::CloseArray() {
+ Buf.EndList();
+ }
- void TJsonWriter::Write(const TStringBuf& value) {
- if (ValidateUtf8 && !IsUtf(value))
- throw yexception() << "JSON writer: invalid UTF-8";
- if (Buf.KeyExpected()) {
- Buf.WriteKey(value);
+ void TJsonWriter::Write(const TStringBuf& value) {
+ if (ValidateUtf8 && !IsUtf(value))
+ throw yexception() << "JSON writer: invalid UTF-8";
+ if (Buf.KeyExpected()) {
+ Buf.WriteKey(value);
} else {
- if (DontEscapeStrings) {
- Buf.UnsafeWriteValue(TString("\"") + value + '"');
- } else {
- Buf.WriteString(value);
- }
+ if (DontEscapeStrings) {
+ Buf.UnsafeWriteValue(TString("\"") + value + '"');
+ } else {
+ Buf.WriteString(value);
+ }
}
}
- void TJsonWriter::WriteNull() {
- Buf.WriteNull();
- }
+ void TJsonWriter::WriteNull() {
+ Buf.WriteNull();
+ }
- void TJsonWriter::Write(float value) {
+ void TJsonWriter::Write(float value) {
Buf.WriteFloat(value, FloatToStringMode, FloatNDigits);
- }
+ }
- void TJsonWriter::Write(double value) {
+ void TJsonWriter::Write(double value) {
Buf.WriteDouble(value, FloatToStringMode, DoubleNDigits);
- }
+ }
- void TJsonWriter::Write(long long value) {
- Buf.WriteLongLong(value);
- }
+ void TJsonWriter::Write(long long value) {
+ Buf.WriteLongLong(value);
+ }
- void TJsonWriter::Write(unsigned long long value) {
- Buf.WriteULongLong(value);
- }
+ void TJsonWriter::Write(unsigned long long value) {
+ Buf.WriteULongLong(value);
+ }
- void TJsonWriter::Write(bool value) {
- Buf.WriteBool(value);
- }
+ void TJsonWriter::Write(bool value) {
+ Buf.WriteBool(value);
+ }
- namespace {
- struct TLessStrPtr {
- bool operator()(const TString* a, const TString* b) const {
- return *a < *b;
- }
- };
- }
+ namespace {
+ struct TLessStrPtr {
+ bool operator()(const TString* a, const TString* b) const {
+ return *a < *b;
+ }
+ };
+ }
- void TJsonWriter::Write(const TJsonValue* v) {
+ void TJsonWriter::Write(const TJsonValue* v) {
Buf.WriteJsonValue(v, SortKeys, FloatToStringMode, DoubleNDigits);
- }
+ }
void TJsonWriter::Write(const TJsonValue& v) {
Buf.WriteJsonValue(&v, SortKeys, FloatToStringMode, DoubleNDigits);
}
- TString WriteJson(const TJsonValue* value, bool formatOutput, bool sortkeys, bool validateUtf8) {
- TStringStream ss;
- WriteJson(&ss, value, formatOutput, sortkeys, validateUtf8);
- return ss.Str();
- }
-
- TString WriteJson(const TJsonValue& value, bool formatOutput, bool sortkeys, bool validateUtf8) {
- TStringStream ss;
- WriteJson(&ss, &value, formatOutput, sortkeys, validateUtf8);
- return ss.Str();
- }
-
- void WriteJson(IOutputStream* out, const TJsonValue* val, bool formatOutput, bool sortkeys, bool validateUtf8) {
- TJsonWriter w(out, formatOutput, sortkeys, validateUtf8);
- w.Write(val);
- w.Flush();
- }
-
- void WriteJson(IOutputStream* out, const TJsonValue* val, const TJsonWriterConfig& config) {
- TJsonWriter w(out, config, true);
- w.Write(val);
- w.Flush();
- }
+ TString WriteJson(const TJsonValue* value, bool formatOutput, bool sortkeys, bool validateUtf8) {
+ TStringStream ss;
+ WriteJson(&ss, value, formatOutput, sortkeys, validateUtf8);
+ return ss.Str();
+ }
+
+ TString WriteJson(const TJsonValue& value, bool formatOutput, bool sortkeys, bool validateUtf8) {
+ TStringStream ss;
+ WriteJson(&ss, &value, formatOutput, sortkeys, validateUtf8);
+ return ss.Str();
+ }
+
+ void WriteJson(IOutputStream* out, const TJsonValue* val, bool formatOutput, bool sortkeys, bool validateUtf8) {
+ TJsonWriter w(out, formatOutput, sortkeys, validateUtf8);
+ w.Write(val);
+ w.Flush();
+ }
+
+ void WriteJson(IOutputStream* out, const TJsonValue* val, const TJsonWriterConfig& config) {
+ TJsonWriter w(out, config, true);
+ w.Write(val);
+ w.Flush();
+ }
}