aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/json
diff options
context:
space:
mode:
authormowgli <mowgli@yandex-team.ru>2022-02-10 16:49:25 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:25 +0300
commit56c39b3cf908e7202b1f7551a1653681e8015607 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/json
parent89afbbe4ca0e02e386dd4df08f7945f190dc1b84 (diff)
downloadydb-56c39b3cf908e7202b1f7551a1653681e8015607.tar.gz
Restoring authorship annotation for <mowgli@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/json')
-rw-r--r--library/cpp/json/writer/json.cpp22
-rw-r--r--library/cpp/json/writer/json.h52
-rw-r--r--library/cpp/json/writer/json_value.cpp30
-rw-r--r--library/cpp/json/writer/json_value.h10
-rw-r--r--library/cpp/json/writer/json_value_ut.cpp120
5 files changed, 117 insertions, 117 deletions
diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp
index b646d459c1..02370c2d79 100644
--- a/library/cpp/json/writer/json.cpp
+++ b/library/cpp/json/writer/json.cpp
@@ -28,8 +28,8 @@ namespace NJsonWriter {
Stack.reserve(64); // should be enough for most cases
StackPush(JE_OUTER_SPACE);
- }
-
+ }
+
static const char* EntityToStr(EJsonEntity e) {
switch (e) {
case JE_OUTER_SPACE:
@@ -44,7 +44,7 @@ namespace NJsonWriter {
return "JE_unknown";
}
}
-
+
inline void TBuf::StackPush(EJsonEntity e) {
Stack.push_back(e);
}
@@ -74,7 +74,7 @@ namespace NJsonWriter {
NeedComma = true;
NeedNewline = true;
}
-
+
inline void TBuf::CheckAndPop(EJsonEntity e) {
if (Y_UNLIKELY(StackTop() != e)) {
ythrow TError() << "JSON writer: unexpected value "
@@ -91,8 +91,8 @@ namespace NJsonWriter {
return;
PrintWhitespaces(Max(0, indentation), true);
- }
-
+ }
+
void TBuf::PrintWhitespaces(size_t count, bool prependWithNewLine) {
static constexpr TStringBuf whitespacesTemplate = "\n ";
static_assert(whitespacesTemplate[0] == '\n');
@@ -112,13 +112,13 @@ namespace NJsonWriter {
RawWriteChar(',');
}
NeedComma = true;
-
+
if (NeedNewline) {
PrintIndentation(false);
}
NeedNewline = true;
}
-
+
inline void TBuf::BeginValue() {
if (Y_UNLIKELY(KeyExpected())) {
ythrow TError() << "JSON writer: value written, "
@@ -375,9 +375,9 @@ namespace NJsonWriter {
return false;
}
-
-#undef MATCH
-
+
+#undef MATCH
+
static bool LessStrPtr(const TString* a, const TString* b) {
return *a < *b;
}
diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h
index 07c3b9d0d1..0aae2531b9 100644
--- a/library/cpp/json/writer/json.h
+++ b/library/cpp/json/writer/json.h
@@ -43,8 +43,8 @@ namespace NJsonWriter {
public:
TBuf(EHtmlEscapeMode mode = HEM_DONT_ESCAPE_HTML, IOutputStream* stream = nullptr);
- TValueContext WriteString(const TStringBuf& s, EHtmlEscapeMode hem);
- TValueContext WriteString(const TStringBuf& s);
+ TValueContext WriteString(const TStringBuf& s, EHtmlEscapeMode hem);
+ TValueContext WriteString(const TStringBuf& s);
TValueContext WriteInt(int i);
TValueContext WriteLongLong(long long i);
TValueContext WriteULongLong(unsigned long long i);
@@ -58,15 +58,15 @@ namespace NJsonWriter {
TBuf& EndList();
TPairContext BeginObject();
- TAfterColonContext WriteKey(const TStringBuf& key, EHtmlEscapeMode hem);
- TAfterColonContext WriteKey(const TStringBuf& key);
+ TAfterColonContext WriteKey(const TStringBuf& key, EHtmlEscapeMode hem);
+ TAfterColonContext WriteKey(const TStringBuf& key);
TAfterColonContext UnsafeWriteKey(const TStringBuf& key);
- bool KeyExpected() const {
- return Stack.back() == JE_OBJECT;
- }
+ bool KeyExpected() const {
+ return Stack.back() == JE_OBJECT;
+ }
//! deprecated, do not use in new code
- TAfterColonContext CompatWriteKeyWithoutQuotes(const TStringBuf& key);
+ TAfterColonContext CompatWriteKeyWithoutQuotes(const TStringBuf& key);
TBuf& EndObject();
@@ -102,7 +102,7 @@ namespace NJsonWriter {
* j.UnsafeWriteValue("[1, 2, 3, \"o'clock\", 4, \"o'clock rock\"]");
*
* As in all of the Unsafe* functions, no escaping is done. */
- void UnsafeWriteValue(const TStringBuf& s);
+ void UnsafeWriteValue(const TStringBuf& s);
void UnsafeWriteValue(const char* s, size_t len);
/*** When in the context of an object, write a literal string
@@ -114,10 +114,10 @@ namespace NJsonWriter {
* j.EndObject();
*
* As in all of the Unsafe* functions, no escaping is done. */
- TPairContext UnsafeWritePair(const TStringBuf& s);
+ TPairContext UnsafeWritePair(const TStringBuf& s);
/*** Copy the supplied string directly into the output stream. */
- void UnsafeWriteRawBytes(const TStringBuf& s);
+ void UnsafeWriteRawBytes(const TStringBuf& s);
void UnsafeWriteRawBytes(const char* c, size_t len);
TBufState State() const;
@@ -129,21 +129,21 @@ namespace NJsonWriter {
void EndValue();
void BeginKey();
void RawWriteChar(char c);
- bool EscapedWriteChar(const char* b, const char* c, EHtmlEscapeMode hem);
+ bool EscapedWriteChar(const char* b, const char* c, EHtmlEscapeMode hem);
void WriteBareString(const TStringBuf s, EHtmlEscapeMode hem);
void WriteComma();
void PrintIndentation(bool closing);
void PrintWhitespaces(size_t count, bool prependWithNewLine);
void WriteHexEscape(unsigned char c);
- void StackPush(EJsonEntity e);
- void StackPop();
- void CheckAndPop(EJsonEntity e);
- EJsonEntity StackTop() const;
-
+ void StackPush(EJsonEntity e);
+ void StackPop();
+ void CheckAndPop(EJsonEntity e);
+ EJsonEntity StackTop() const;
+
template <class TFloat>
TValueContext WriteFloatImpl(TFloat f, EFloatToStringMode mode, int ndigits);
-
+
private:
IOutputStream* Stream;
THolder<TStringStream> StringStream;
@@ -160,8 +160,8 @@ namespace NJsonWriter {
// Please don't try to instantiate the classes declared below this point.
- template <typename TOutContext>
- class TValueWriter {
+ template <typename TOutContext>
+ class TValueWriter {
public:
TOutContext WriteNull();
TOutContext WriteString(const TStringBuf&);
@@ -221,19 +221,19 @@ namespace NJsonWriter {
class TPairContext {
public:
- TAfterColonContext WriteKey(const TStringBuf& s, EHtmlEscapeMode hem) {
+ TAfterColonContext WriteKey(const TStringBuf& s, EHtmlEscapeMode hem) {
return Buf.WriteKey(s, hem);
}
- TAfterColonContext WriteKey(const TStringBuf& s) {
+ TAfterColonContext WriteKey(const TStringBuf& s) {
return Buf.WriteKey(s);
}
TAfterColonContext UnsafeWriteKey(const TStringBuf& s) {
return Buf.UnsafeWriteKey(s);
}
- TAfterColonContext CompatWriteKeyWithoutQuotes(const TStringBuf& s) {
+ TAfterColonContext CompatWriteKeyWithoutQuotes(const TStringBuf& s) {
return Buf.CompatWriteKeyWithoutQuotes(s);
}
- TPairContext UnsafeWritePair(const TStringBuf& s) {
+ TPairContext UnsafeWritePair(const TStringBuf& s) {
return Buf.UnsafeWritePair(s);
}
TBuf& EndObject() {
@@ -243,8 +243,8 @@ namespace NJsonWriter {
private:
TPairContext(TBuf& buf)
: Buf(buf)
- {
- }
+ {
+ }
friend class TBuf;
friend class TValueWriter<TPairContext>;
diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp
index e92099e44c..c61e8d1dc4 100644
--- a/library/cpp/json/writer/json_value.cpp
+++ b/library/cpp/json/writer/json_value.cpp
@@ -3,7 +3,7 @@
#include <util/generic/ymath.h>
#include <util/generic/ylimits.h>
-#include <util/generic/utility.h>
+#include <util/generic/utility.h>
#include <util/generic/singleton.h>
#include <util/stream/str.h>
#include <util/stream/output.h>
@@ -286,8 +286,8 @@ namespace NJson {
TArray::iterator it = Value.Array->begin() + index;
Value.Array->erase(it);
}
- }
-
+ }
+
void TJsonValue::Clear() noexcept {
switch (Type) {
case JSON_STRING:
@@ -714,8 +714,8 @@ namespace NJson {
return false;
*value = Value.Array;
- return true;
- }
+ return true;
+ }
bool TJsonValue::GetValue(const size_t index, TJsonValue* value) const {
const TJsonValue* tmp = nullptr;
@@ -724,7 +724,7 @@ namespace NJson {
return true;
}
return false;
- }
+ }
bool TJsonValue::GetValue(const TStringBuf key, TJsonValue* value) const {
const TJsonValue* tmp = nullptr;
@@ -733,15 +733,15 @@ namespace NJson {
return true;
}
return false;
- }
+ }
bool TJsonValue::GetValuePointer(const size_t index, const TJsonValue** value) const noexcept {
if (Type == JSON_ARRAY && index < Value.Array->size()) {
*value = &(*Value.Array)[index];
- return true;
- }
+ return true;
+ }
return false;
- }
+ }
bool TJsonValue::GetValuePointer(const TStringBuf key, const TJsonValue** value) const noexcept {
if (Type == JSON_MAP) {
@@ -882,8 +882,8 @@ namespace NJson {
const TJsonValue* TJsonValue::GetValueByPath(const TStringBuf key, char delim) const noexcept {
return GetValuePtrByPath<false>(this, key, delim);
- }
-
+ }
+
TJsonValue* TJsonValue::GetValueByPath(const TStringBuf key, char delim) noexcept {
return GetValuePtrByPath<false>(this, key, delim);
}
@@ -945,11 +945,11 @@ namespace NJson {
case JSON_INTEGER: {
return (rhs.IsInteger() && GetInteger() == rhs.GetInteger());
}
-
+
case JSON_UINTEGER: {
return (rhs.IsUInteger() && GetUInteger() == rhs.GetUInteger());
}
-
+
case JSON_STRING: {
return (rhs.IsString() && Value.String == rhs.Value.String);
}
@@ -978,7 +978,7 @@ namespace NJson {
} else {
std::memcpy(&output.Value, &Value, sizeof(Value));
}
-
+
output.Type = Type;
Type = JSON_UNDEFINED;
}
diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h
index e625c79eb6..3f0f50bc4c 100644
--- a/library/cpp/json/writer/json_value.h
+++ b/library/cpp/json/writer/json_value.h
@@ -99,12 +99,12 @@ namespace NJson {
void EraseValue(TStringBuf key);
void EraseValue(size_t index);
-
+
TJsonValue& operator[](size_t idx);
TJsonValue& operator[](const TStringBuf& key);
const TJsonValue& operator[](size_t idx) const noexcept;
const TJsonValue& operator[](const TStringBuf& key) const noexcept;
-
+
bool GetBoolean() const;
long long GetInteger() const;
unsigned long long GetUInteger() const;
@@ -164,7 +164,7 @@ namespace NJson {
bool IsString() const noexcept;
bool IsMap() const noexcept;
bool IsArray() const noexcept;
-
+
/// @return true if JSON_INTEGER or (JSON_UINTEGER and Value <= Max<long long>)
bool IsInteger() const noexcept;
@@ -192,7 +192,7 @@ namespace NJson {
void Load(IInputStream* s);
static const TJsonValue UNDEFINED;
-
+
private:
EJsonValueType Type = JSON_UNDEFINED;
union TValueUnion {
@@ -218,7 +218,7 @@ namespace NJson {
@throw yexception if Back shouldn't be called on the object.
*/
void BackChecks() const;
- };
+ };
inline bool GetBoolean(const TJsonValue& jv, size_t index, bool* value) noexcept {
return jv[index].GetBoolean(value);
diff --git a/library/cpp/json/writer/json_value_ut.cpp b/library/cpp/json/writer/json_value_ut.cpp
index 31540983c0..dc7f6affdf 100644
--- a/library/cpp/json/writer/json_value_ut.cpp
+++ b/library/cpp/json/writer/json_value_ut.cpp
@@ -8,34 +8,34 @@ using namespace NJson;
Y_UNIT_TEST_SUITE(TJsonValueTest) {
Y_UNIT_TEST(UndefTest) {
- TJsonValue undef;
- TJsonValue null(JSON_NULL);
- TJsonValue _false(false);
- TJsonValue zeroInt(0);
- TJsonValue zeroDouble(0.0);
- TJsonValue emptyStr("");
- TJsonValue emptyArray(JSON_ARRAY);
- TJsonValue emptyMap(JSON_MAP);
-
- UNIT_ASSERT(!undef.IsDefined());
+ TJsonValue undef;
+ TJsonValue null(JSON_NULL);
+ TJsonValue _false(false);
+ TJsonValue zeroInt(0);
+ TJsonValue zeroDouble(0.0);
+ TJsonValue emptyStr("");
+ TJsonValue emptyArray(JSON_ARRAY);
+ TJsonValue emptyMap(JSON_MAP);
+
+ UNIT_ASSERT(!undef.IsDefined());
UNIT_ASSERT(!null.IsDefined()); // json NULL is undefined too!
- UNIT_ASSERT(_false.IsDefined());
- UNIT_ASSERT(zeroInt.IsDefined());
- UNIT_ASSERT(zeroDouble.IsDefined());
- UNIT_ASSERT(emptyStr.IsDefined());
- UNIT_ASSERT(emptyArray.IsDefined());
- UNIT_ASSERT(emptyMap.IsDefined());
-
- UNIT_ASSERT(undef == TJsonValue());
- UNIT_ASSERT(undef != null);
- UNIT_ASSERT(undef != _false);
- UNIT_ASSERT(undef != zeroInt);
- UNIT_ASSERT(undef != zeroDouble);
- UNIT_ASSERT(undef != emptyStr);
- UNIT_ASSERT(undef != emptyArray);
- UNIT_ASSERT(undef != emptyMap);
- }
-
+ UNIT_ASSERT(_false.IsDefined());
+ UNIT_ASSERT(zeroInt.IsDefined());
+ UNIT_ASSERT(zeroDouble.IsDefined());
+ UNIT_ASSERT(emptyStr.IsDefined());
+ UNIT_ASSERT(emptyArray.IsDefined());
+ UNIT_ASSERT(emptyMap.IsDefined());
+
+ UNIT_ASSERT(undef == TJsonValue());
+ UNIT_ASSERT(undef != null);
+ UNIT_ASSERT(undef != _false);
+ UNIT_ASSERT(undef != zeroInt);
+ UNIT_ASSERT(undef != zeroDouble);
+ UNIT_ASSERT(undef != emptyStr);
+ UNIT_ASSERT(undef != emptyArray);
+ UNIT_ASSERT(undef != emptyMap);
+ }
+
Y_UNIT_TEST(DefaultCompareTest) {
{
TJsonValue lhs;
@@ -208,31 +208,31 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
UNIT_ASSERT(rhs != lhs);
}
}
-
+
Y_UNIT_TEST(SwapTest) {
- {
- TJsonValue lhs;
- lhs.InsertValue("a", "b");
- TJsonValue lhsCopy = lhs;
-
- TJsonValue rhs(JSON_NULL);
- TJsonValue rhsCopy = rhs;
-
- UNIT_ASSERT(lhs == lhsCopy);
- UNIT_ASSERT(rhs == rhsCopy);
-
- lhs.Swap(rhs);
-
- UNIT_ASSERT(rhs == lhsCopy);
- UNIT_ASSERT(lhs == rhsCopy);
-
- lhs.Swap(rhs);
-
- UNIT_ASSERT(lhs == lhsCopy);
- UNIT_ASSERT(rhs == rhsCopy);
- }
- }
-
+ {
+ TJsonValue lhs;
+ lhs.InsertValue("a", "b");
+ TJsonValue lhsCopy = lhs;
+
+ TJsonValue rhs(JSON_NULL);
+ TJsonValue rhsCopy = rhs;
+
+ UNIT_ASSERT(lhs == lhsCopy);
+ UNIT_ASSERT(rhs == rhsCopy);
+
+ lhs.Swap(rhs);
+
+ UNIT_ASSERT(rhs == lhsCopy);
+ UNIT_ASSERT(lhs == rhsCopy);
+
+ lhs.Swap(rhs);
+
+ UNIT_ASSERT(lhs == lhsCopy);
+ UNIT_ASSERT(rhs == rhsCopy);
+ }
+ }
+
Y_UNIT_TEST(GetValueByPathTest) {
{
TJsonValue lhs;
@@ -250,15 +250,15 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
UNIT_ASSERT(!lhs.GetValueByPath("l/a/c/se", result, '/'));
UNIT_ASSERT(lhs.GetValueByPath("l/a/c", result, '/'));
UNIT_ASSERT(result.GetStringRobust() == "{\"e\":\"f\"}");
-
- // faster TStringBuf version
- UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l", '/'), last);
- UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l/a", '/'), second);
- UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l/a/c", '/'), first);
- UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l.a.c.e", '.'), "f");
- UNIT_ASSERT_EQUAL(lhs.GetValueByPath("l/a/c/e/x", '/'), NULL);
- UNIT_ASSERT_EQUAL(lhs.GetValueByPath("a/c/e/x", '/'), NULL);
- UNIT_ASSERT_EQUAL(lhs.GetValueByPath("nokey", '/'), NULL);
+
+ // faster TStringBuf version
+ UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l", '/'), last);
+ UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l/a", '/'), second);
+ UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l/a/c", '/'), first);
+ UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("l.a.c.e", '.'), "f");
+ UNIT_ASSERT_EQUAL(lhs.GetValueByPath("l/a/c/e/x", '/'), NULL);
+ UNIT_ASSERT_EQUAL(lhs.GetValueByPath("a/c/e/x", '/'), NULL);
+ UNIT_ASSERT_EQUAL(lhs.GetValueByPath("nokey", '/'), NULL);
UNIT_ASSERT_EQUAL(*lhs.GetValueByPath("", '/'), lhs); // itself
TJsonValue array;