aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/json
diff options
context:
space:
mode:
authorantoshkka <antoshkka@yandex-team.ru>2022-02-10 16:50:14 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:14 +0300
commitecc19a1fc1e15d78a9279514cb11edd9e808d600 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/json
parent90277959ac43a22ec25e7b78b1a2b4f610530d51 (diff)
downloadydb-ecc19a1fc1e15d78a9279514cb11edd9e808d600.tar.gz
Restoring authorship annotation for <antoshkka@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/json')
-rw-r--r--library/cpp/json/writer/json_value.cpp34
-rw-r--r--library/cpp/json/writer/json_value.h22
-rw-r--r--library/cpp/json/writer/json_value_ut.cpp26
3 files changed, 41 insertions, 41 deletions
diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp
index 2a45c7d7e8..c61e8d1dc4 100644
--- a/library/cpp/json/writer/json_value.cpp
+++ b/library/cpp/json/writer/json_value.cpp
@@ -118,7 +118,7 @@ namespace NJson {
return *this;
TJsonValue tmp(std::move(val));
tmp.Swap(*this);
- return *this;
+ return *this;
}
TJsonValue::TJsonValue(const bool value) noexcept {
@@ -165,7 +165,7 @@ namespace NJson {
SetType(JSON_STRING);
Value.String = std::move(value);
}
-
+
TJsonValue::TJsonValue(const TStringBuf value) {
SetType(JSON_STRING);
Value.String = value;
@@ -222,7 +222,7 @@ namespace NJson {
SetType(JSON_MAP);
return (*Value.Map)[key] = value;
}
-
+
TJsonValue& TJsonValue::InsertValue(const TStringBuf key, const TJsonValue& value) {
SetType(JSON_MAP);
return (*Value.Map)[key] = value;
@@ -242,17 +242,17 @@ namespace NJson {
SetType(JSON_MAP);
return (*Value.Map)[key] = std::move(value);
}
-
+
TJsonValue& TJsonValue::InsertValue(const char* key, TJsonValue&& value) {
SetType(JSON_MAP);
return (*Value.Map)[key] = std::move(value);
}
-
+
TJsonValue& TJsonValue::Back() {
BackChecks();
return Value.Array->back();
}
-
+
const TJsonValue& TJsonValue::Back() const {
BackChecks();
return Value.Array->back();
@@ -277,7 +277,7 @@ namespace NJson {
Value.Map->erase(it);
}
}
-
+
void TJsonValue::EraseValue(const size_t index) {
if (IsArray()) {
if (index >= Value.Array->size()) {
@@ -821,20 +821,20 @@ namespace NJson {
TPtr* CreateOrNullptr(TPtr* p, T key, std::true_type /*create*/) {
return &(*p)[key];
}
-
+
template <class TPtr, class T>
TPtr* CreateOrNullptr(const TPtr* p, T key, std::false_type /*create*/) noexcept {
const TPtr* const next = &(*p)[key];
return next->IsDefined() ? const_cast<TPtr*>(next) : nullptr;
}
-
+
template <bool Create, class TJsonPtr>
TJsonPtr GetValuePtrByPath(TJsonPtr currentJson, TStringBuf path, char delimiter) noexcept(!Create) {
static_assert(
!(Create && std::is_const<std::remove_pointer_t<TJsonPtr>>::value),
"TJsonPtr must be a `TJsonValue*` if `Create` is true");
constexpr std::integral_constant<bool, Create> create_tag{};
-
+
while (!path.empty()) {
size_t index = 0;
const TStringBuf step = path.NextTok(delimiter);
@@ -847,12 +847,12 @@ namespace NJson {
if (!currentJson) {
return nullptr;
}
- }
-
+ }
+
return currentJson;
}
} // anonymous namespace
-
+
bool TJsonValue::GetValueByPath(const TStringBuf path, TJsonValue& result, char delimiter) const {
const TJsonValue* const ptr = GetValuePtrByPath<false>(this, path, delimiter);
if (ptr) {
@@ -887,7 +887,7 @@ namespace NJson {
TJsonValue* TJsonValue::GetValueByPath(const TStringBuf key, char delim) noexcept {
return GetValuePtrByPath<false>(this, key, delim);
}
-
+
void TJsonValue::DoScan(const TString& path, TJsonValue* parent, IScanCallback& callback) {
if (!callback.Do(path, parent, *this)) {
return;
@@ -968,8 +968,8 @@ namespace NJson {
Y_ASSERT(false && "Unknown type.");
return false;
}
- }
-
+ }
+
void TJsonValue::SwapWithUndefined(TJsonValue& output) noexcept {
if (Type == JSON_STRING) {
static_assert(std::is_nothrow_move_constructible<TString>::value, "noexcept violation! Add some try {} catch (...) logic");
@@ -982,7 +982,7 @@ namespace NJson {
output.Type = Type;
Type = JSON_UNDEFINED;
}
-
+
void TJsonValue::Swap(TJsonValue& rhs) noexcept {
TJsonValue tmp(std::move(*this));
rhs.SwapWithUndefined(*this);
diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h
index e880fdae51..3f0f50bc4c 100644
--- a/library/cpp/json/writer/json_value.h
+++ b/library/cpp/json/writer/json_value.h
@@ -152,7 +152,7 @@ namespace NJson {
bool GetValuePointer(size_t index, const TJsonValue** value) const noexcept;
bool GetValuePointer(TStringBuf key, const TJsonValue** value) const noexcept;
bool GetValuePointer(TStringBuf key, TJsonValue** value) noexcept;
-
+
// Checking for defined non-null value
bool IsDefined() const noexcept {
return Type != JSON_UNDEFINED && Type != JSON_NULL;
@@ -223,26 +223,26 @@ namespace NJson {
inline bool GetBoolean(const TJsonValue& jv, size_t index, bool* value) noexcept {
return jv[index].GetBoolean(value);
}
-
+
inline bool GetInteger(const TJsonValue& jv, size_t index, long long* value) noexcept {
return jv[index].GetInteger(value);
}
-
+
inline bool GetUInteger(const TJsonValue& jv, size_t index, unsigned long long* value) noexcept {
return jv[index].GetUInteger(value);
}
-
+
inline bool GetDouble(const TJsonValue& jv, size_t index, double* value) noexcept {
return jv[index].GetDouble(value);
}
-
+
inline bool GetString(const TJsonValue& jv, size_t index, TString* value) {
return jv[index].GetString(value);
}
-
+
bool GetMapPointer(const TJsonValue& jv, size_t index, const TJsonValue::TMapType** value);
bool GetArrayPointer(const TJsonValue& jv, size_t index, const TJsonValue::TArray** value);
-
+
inline bool GetBoolean(const TJsonValue& jv, TStringBuf key, bool* value) noexcept {
return jv[key].GetBoolean(value);
}
@@ -254,15 +254,15 @@ namespace NJson {
inline bool GetUInteger(const TJsonValue& jv, TStringBuf key, unsigned long long* value) noexcept {
return jv[key].GetUInteger(value);
}
-
+
inline bool GetDouble(const TJsonValue& jv, TStringBuf key, double* value) noexcept {
return jv[key].GetDouble(value);
}
-
+
inline bool GetString(const TJsonValue& jv, TStringBuf key, TString* value) {
return jv[key].GetString(value);
}
-
+
bool GetMapPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TMapType** value);
bool GetArrayPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TArray** value);
@@ -291,4 +291,4 @@ namespace NJson {
GetArraySafe() = TJsonValue::TArray(list);
}
};
-}
+}
diff --git a/library/cpp/json/writer/json_value_ut.cpp b/library/cpp/json/writer/json_value_ut.cpp
index c41a227cc9..dc7f6affdf 100644
--- a/library/cpp/json/writer/json_value_ut.cpp
+++ b/library/cpp/json/writer/json_value_ut.cpp
@@ -608,21 +608,21 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
}
Y_UNIT_TEST(MoveSubpartToSelf) {
- TJsonValue json;
- json[0] = "testing 0";
- json[1] = "testing 1";
- json[2] = "testing 2";
- json = std::move(json[1]);
- UNIT_ASSERT_VALUES_EQUAL(json.GetString(), "testing 1");
-
- const char* longTestString =
- "Testing TJsonValue& operator=(TJsonValue&&) subpart self moving "
+ TJsonValue json;
+ json[0] = "testing 0";
+ json[1] = "testing 1";
+ json[2] = "testing 2";
+ json = std::move(json[1]);
+ UNIT_ASSERT_VALUES_EQUAL(json.GetString(), "testing 1");
+
+ const char* longTestString =
+ "Testing TJsonValue& operator=(TJsonValue&&) subpart self moving "
"after TJsonValue was constrcuted from TString&&.";
-
+
json["hello"] = TString{longTestString};
- json = std::move(json["hello"]);
- UNIT_ASSERT_VALUES_EQUAL(json.GetString(), longTestString);
- }
+ json = std::move(json["hello"]);
+ UNIT_ASSERT_VALUES_EQUAL(json.GetString(), longTestString);
+ }
Y_UNIT_TEST(TJsonArrayMapConstructor) {
TJsonMap emptyMap;