summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornae202 <[email protected]>2025-09-23 07:48:35 +0300
committernae202 <[email protected]>2025-09-23 08:03:21 +0300
commit63774bc851bb76e24f369ef4e0328e5f05edbb4b (patch)
treed3226ed9a5f200097949f6001a7e3183aff7adfa
parentf4cbf746a0b6649479cfb305eceababced0ac10a (diff)
Style fix
commit_hash:d506e2a0f2770f3662449a3711e976499eb9ccbb
-rw-r--r--library/cpp/json/common/defs.h3
-rw-r--r--library/cpp/json/converter/converter.h55
-rw-r--r--library/cpp/json/converter/ut/test_conversion.cpp11
-rw-r--r--library/cpp/json/easy_parse/json_easy_parser.cpp78
-rw-r--r--library/cpp/json/easy_parse/json_easy_parser.h2
-rw-r--r--library/cpp/json/easy_parse/json_easy_parser_impl.h4
-rw-r--r--library/cpp/json/fast_sax/parser.h2
-rw-r--r--library/cpp/json/fuzzy_test/main.cpp6
-rw-r--r--library/cpp/json/json_prettifier.cpp17
-rw-r--r--library/cpp/json/json_prettifier.h2
-rw-r--r--library/cpp/json/json_reader.cpp26
-rw-r--r--library/cpp/json/json_reader.h2
-rw-r--r--library/cpp/json/json_value.h2
-rw-r--r--library/cpp/json/json_writer.cpp7
-rw-r--r--library/cpp/json/json_writer.h2
-rw-r--r--library/cpp/json/ordered_maps/json_ordered.cpp38
-rw-r--r--library/cpp/json/ordered_maps/json_ordered.h50
-rw-r--r--library/cpp/json/ordered_maps/json_reader_ordered.cpp26
-rw-r--r--library/cpp/json/ordered_maps/json_reader_ordered.h2
-rw-r--r--library/cpp/json/ordered_maps/json_value_ordered.cpp226
-rw-r--r--library/cpp/json/ordered_maps/json_value_ordered.h10
-rw-r--r--library/cpp/json/ordered_maps/json_writer_ordered.cpp7
-rw-r--r--library/cpp/json/ordered_maps/json_writer_ordered.h2
-rw-r--r--library/cpp/json/ordered_maps/ut/json_ordered_ut.cpp2
-rw-r--r--library/cpp/json/ordered_maps/ut/json_reader_fast_ordered_ut.cpp22
-rw-r--r--library/cpp/json/ordered_maps/ut/json_reader_nan_ordered_ut.cpp8
-rw-r--r--library/cpp/json/ordered_maps/ut/json_reader_ordered_ut.cpp8
-rw-r--r--library/cpp/json/ordered_maps/ut/json_value_ordered_ut.cpp28
-rw-r--r--library/cpp/json/ordered_maps/ut/json_writer_ordered_ut.cpp4
-rw-r--r--library/cpp/json/rapidjson_helpers.h6
-rw-r--r--library/cpp/json/ut/json_prettifier_ut.cpp2
-rw-r--r--library/cpp/json/ut/json_reader_fast_ut.cpp22
-rw-r--r--library/cpp/json/ut/json_reader_nan_ut.cpp8
-rw-r--r--library/cpp/json/ut/json_reader_ut.cpp8
-rw-r--r--library/cpp/json/ut/json_saveload_ut.cpp3
-rw-r--r--library/cpp/json/ut/json_writer_ut.cpp4
-rw-r--r--library/cpp/json/writer/json.cpp35
-rw-r--r--library/cpp/json/writer/json.h50
-rw-r--r--library/cpp/json/writer/json_ut.cpp2
-rw-r--r--library/cpp/json/writer/json_value.cpp238
-rw-r--r--library/cpp/json/writer/json_value.h10
-rw-r--r--library/cpp/json/writer/json_value_ut.cpp21
-rw-r--r--library/cpp/json/yson/json2yson.cpp5
-rw-r--r--library/cpp/json/yson/json2yson.h2
-rw-r--r--library/cpp/json/yson/json2yson_ut.cpp2
45 files changed, 513 insertions, 557 deletions
diff --git a/library/cpp/json/common/defs.h b/library/cpp/json/common/defs.h
index ae3985508be..331c687665f 100644
--- a/library/cpp/json/common/defs.h
+++ b/library/cpp/json/common/defs.h
@@ -35,8 +35,9 @@ namespace NJson {
bool GetHaveErrors() const {
return HaveErrors;
}
+
protected:
bool ThrowException;
bool HaveErrors = false;
};
-}
+} // namespace NJson
diff --git a/library/cpp/json/converter/converter.h b/library/cpp/json/converter/converter.h
index 4e92b2e0cf0..e741b54247a 100644
--- a/library/cpp/json/converter/converter.h
+++ b/library/cpp/json/converter/converter.h
@@ -10,21 +10,20 @@
#include <util/generic/map.h>
#include <util/generic/maybe.h>
-
namespace NJson {
- template<typename T>
+ template <typename T>
struct TConverter {
};
namespace {
- template<typename T>
+ template <typename T>
struct TDefaultEncoder {
static inline TJsonValue Encode(T value) {
return TJsonValue(value);
}
};
- template<typename T, typename E>
+ template <typename T, typename E>
struct TDefaultArrayEncoder {
static TJsonValue Encode(const T& value) {
TJsonValue result(NJson::JSON_ARRAY);
@@ -36,7 +35,7 @@ namespace NJson {
}
};
- template<typename T, typename E>
+ template <typename T, typename E>
struct TDefaultArrayDecoder {
static T Decode(const TJsonValue& value) {
T result;
@@ -47,11 +46,11 @@ namespace NJson {
}
};
- template<typename T, typename E>
+ template <typename T, typename E>
struct TDefaultArrayConverter: public TDefaultArrayEncoder<T, E>, public TDefaultArrayDecoder<T, E> {
};
- template<typename T, typename E>
+ template <typename T, typename E>
struct TDefaultMapEncoder {
static TJsonValue Encode(const T& value) {
TJsonValue result(NJson::JSON_MAP);
@@ -63,7 +62,7 @@ namespace NJson {
}
};
- template<typename T, typename E>
+ template <typename T, typename E>
struct TDefaultMapDecoder {
static T Decode(const TJsonValue& value) {
T result;
@@ -74,12 +73,12 @@ namespace NJson {
}
};
- template<typename T, typename E>
+ template <typename T, typename E>
struct TDefaultMapConverter: public TDefaultMapEncoder<T, E>, public TDefaultMapDecoder<T, E> {
};
- }
+ } // namespace
- template<>
+ template <>
struct TConverter<TJsonValue> {
static TJsonValue Encode(const TJsonValue& value) {
return value;
@@ -90,15 +89,15 @@ namespace NJson {
}
};
- template<>
+ template <>
struct TConverter<bool>: public TDefaultEncoder<bool> {
static inline bool Decode(const TJsonValue& value) {
return value.GetBooleanSafe();
}
};
- template<typename T>
- requires std::is_integral_v<T> && (!std::is_same_v<T, bool>)
+ template <typename T>
+ requires std::is_integral_v<T> && (!std::is_same_v<T, bool>)
struct TConverter<T>: public TDefaultEncoder<T> {
static T Decode(const TJsonValue& value) {
if constexpr (std::is_signed_v<T>) {
@@ -117,26 +116,26 @@ namespace NJson {
}
};
- template<typename T>
- requires std::is_floating_point_v<T>
+ template <typename T>
+ requires std::is_floating_point_v<T>
struct TConverter<T>: public TDefaultEncoder<T> {
static inline T Decode(const TJsonValue& value) {
return static_cast<T>(value.GetDoubleSafe());
}
};
- template<>
+ template <>
struct TConverter<TStringBuf>: public TDefaultEncoder<TStringBuf> {
};
- template<>
+ template <>
struct TConverter<TString>: public TDefaultEncoder<TString> {
static inline TString Decode(const TJsonValue& value) {
return value.GetStringSafe();
}
};
- template<typename T>
+ template <typename T>
struct TConverter<TMaybe<T>> {
static TJsonValue Encode(const TMaybe<T>& value) {
if (value.Defined()) {
@@ -155,35 +154,35 @@ namespace NJson {
}
};
- template<typename T>
+ template <typename T>
struct TConverter<TArrayRef<T>>: public TDefaultArrayEncoder<TArrayRef<T>, T> {
};
- template<typename T>
+ template <typename T>
struct TConverter<TVector<T>>: public TDefaultArrayConverter<TVector<T>, T> {
};
- template<typename T>
+ template <typename T>
struct TConverter<TList<T>>: public TDefaultArrayConverter<TList<T>, T> {
};
- template<typename T>
+ template <typename T>
struct TConverter<TDeque<T>>: public TDefaultArrayConverter<TDeque<T>, T> {
};
- template<typename T>
+ template <typename T>
struct TConverter<THashMap<TStringBuf, T>>: public TDefaultMapEncoder<THashMap<TStringBuf, T>, T> {
};
- template<typename T>
+ template <typename T>
struct TConverter<THashMap<TString, T>>: public TDefaultMapConverter<THashMap<TString, T>, T> {
};
- template<typename T>
+ template <typename T>
struct TConverter<TMap<TStringBuf, T>>: public TDefaultMapEncoder<TMap<TStringBuf, T>, T> {
};
- template<typename T>
+ template <typename T>
struct TConverter<TMap<TString, T>>: public TDefaultMapConverter<TMap<TString, T>, T> {
};
-}
+} // namespace NJson
diff --git a/library/cpp/json/converter/ut/test_conversion.cpp b/library/cpp/json/converter/ut/test_conversion.cpp
index 84027dda75a..4d092759a47 100644
--- a/library/cpp/json/converter/ut/test_conversion.cpp
+++ b/library/cpp/json/converter/ut/test_conversion.cpp
@@ -11,7 +11,6 @@
#include <util/generic/map.h>
#include <util/generic/maybe.h>
-
namespace NJson {
void AssertJsonsEqual(const TJsonValue& actualJson, const TJsonValue& expectedJson) {
const auto actualString = WriteJson(actualJson, /*formatOutput*/ true, /*sortkeys*/ true, /*validateUtf8*/ true);
@@ -24,7 +23,7 @@ namespace NJson {
AssertJsonsEqual(actualJson, expectedJson);
}
- template<typename T>
+ template <typename T>
struct TConverterTester {
using TValues = THashMap<TStringBuf, T>;
@@ -62,8 +61,8 @@ namespace NJson {
}
};
- template<typename T>
- requires std::is_floating_point_v<T>
+ template <typename T>
+ requires std::is_floating_point_v<T>
struct TConverterTester<T> {
using TValues = THashMap<TStringBuf, T>;
@@ -202,5 +201,5 @@ namespace NJson {
},
});
}
- }
-}
+ } // Y_UNIT_TEST_SUITE(ConversionTests)
+} // namespace NJson
diff --git a/library/cpp/json/easy_parse/json_easy_parser.cpp b/library/cpp/json/easy_parse/json_easy_parser.cpp
index 3c781f544bc..ddd9412955c 100644
--- a/library/cpp/json/easy_parse/json_easy_parser.cpp
+++ b/library/cpp/json/easy_parse/json_easy_parser.cpp
@@ -54,21 +54,26 @@ namespace NJson {
private:
static bool PathElementMatch(const TPathElem& templ, const TPathElem& real) {
- if (templ.Type != real.Type)
+ if (templ.Type != real.Type) {
return false;
- if (templ.Type == NImpl::ARRAY)
+ }
+ if (templ.Type == NImpl::ARRAY) {
return templ.ArrayCounter == -1 || templ.ArrayCounter == real.ArrayCounter;
- if (templ.Type == NImpl::MAP_KEY)
+ }
+ if (templ.Type == NImpl::MAP_KEY) {
return templ.Key == ANY_IDENTIFIER || templ.Key == real.Key;
+ }
return true;
}
bool CheckFilter(const TVector<TPathElem>& path) const {
- if (Stack.size() < path.size())
+ if (Stack.size() < path.size()) {
return false;
+ }
for (size_t n = 0; n < path.size(); ++n) {
- if (!PathElementMatch(path[n], Stack[n]))
+ if (!PathElementMatch(path[n], Stack[n])) {
return false;
+ }
}
return true;
}
@@ -90,8 +95,9 @@ namespace NJson {
void IncreaseArrayCounter() {
if (!Stack.empty() && Stack.back().Type == NImpl::ARRAY) {
++Stack.back().ArrayCounter;
- if (ShouldUpdateOnArrayChange)
+ if (ShouldUpdateOnArrayChange) {
UpdateRule();
+ }
}
}
@@ -114,43 +120,49 @@ namespace NJson {
, HasFormatError(false)
{
for (size_t n = 0; n < Parent.Fields.size(); ++n) {
- if (!Parent.Fields[n].Path.empty() && Parent.Fields[n].Path.back().Type == NImpl::ARRAY)
+ if (!Parent.Fields[n].Path.empty() && Parent.Fields[n].Path.back().Type == NImpl::ARRAY) {
ShouldUpdateOnArrayChange = true;
+ }
}
}
bool OnOpenMap() override {
IncreaseArrayCounter();
Stack.push_back(TPathElem(NImpl::MAP));
- if (CurrentFieldIdx >= 0)
+ if (CurrentFieldIdx >= 0) {
HasFormatError = true;
- else
+ } else {
UpdateRule();
+ }
return true;
}
bool OnOpenArray() override {
IncreaseArrayCounter();
Stack.push_back(TPathElem(-1));
- if (CurrentFieldIdx >= 0)
+ if (CurrentFieldIdx >= 0) {
HasFormatError = true;
- else
+ } else {
UpdateRule();
+ }
return true;
}
bool OnCloseMap() override {
- while (!Stack.empty() && Stack.back().Type != NImpl::MAP)
+ while (!Stack.empty() && Stack.back().Type != NImpl::MAP) {
Pop();
- if (!Stack.empty())
+ }
+ if (!Stack.empty()) {
Pop();
+ }
UpdateRule();
return true;
}
bool OnCloseArray() override {
- if (!Stack.empty())
+ if (!Stack.empty()) {
Pop();
+ }
UpdateRule();
return true;
}
@@ -161,10 +173,11 @@ namespace NJson {
UpdateRule();
}
Stack.push_back(TPathElem(TString{key}));
- if (CurrentFieldIdx >= 0)
+ if (CurrentFieldIdx >= 0) {
HasFormatError = true;
- else
+ } else {
UpdateRule();
+ }
return true;
}
@@ -185,17 +198,21 @@ namespace NJson {
}
bool IsOK() const {
- if (HasFormatError)
+ if (HasFormatError) {
return false;
- for (size_t n = 0; n < FieldValues.size(); ++n)
- if (Parent.Fields[n].NonEmpty && FieldValues[n].empty())
+ }
+ for (size_t n = 0; n < FieldValues.size(); ++n) {
+ if (Parent.Fields[n].NonEmpty && FieldValues[n].empty()) {
return false;
+ }
+ }
return true;
}
void WriteTo(IOutputStream& out) const {
- for (size_t n = 0; n < FieldValues.size(); ++n)
+ for (size_t n = 0; n < FieldValues.size(); ++n) {
out << "\t" << FieldValues[n];
+ }
}
void WriteTo(TVector<TString>* res) const {
@@ -220,17 +237,18 @@ namespace NJson {
if (impl.IsOK()) {
impl.WriteTo(res);
return true;
- } else
+ } else {
return false;
+ }
}
- //struct TTestMe {
- // TTestMe() {
- // TJsonParser worker;
- // worker.AddField("/x/y/z", true);
- // TString ret1 = worker.ConvertToTabDelimited("{ \"x\" : { \"y\" : { \"w\" : 1, \"z\" : 2 } } }");
- // TString ret2 = worker.ConvertToTabDelimited(" [1, 2, 3, 4, 5] ");
- // }
- //} testMe;
+ // struct TTestMe {
+ // TTestMe() {
+ // TJsonParser worker;
+ // worker.AddField("/x/y/z", true);
+ // TString ret1 = worker.ConvertToTabDelimited("{ \"x\" : { \"y\" : { \"w\" : 1, \"z\" : 2 } } }");
+ // TString ret2 = worker.ConvertToTabDelimited(" [1, 2, 3, 4, 5] ");
+ // }
+ // } testMe;
-}
+} // namespace NJson
diff --git a/library/cpp/json/easy_parse/json_easy_parser.h b/library/cpp/json/easy_parse/json_easy_parser.h
index 59d7791ab14..0cd668e6fe6 100644
--- a/library/cpp/json/easy_parse/json_easy_parser.h
+++ b/library/cpp/json/easy_parse/json_easy_parser.h
@@ -43,4 +43,4 @@ namespace NJson {
TString ConvertToTabDelimited(const TString& json) const;
bool Parse(const TString& json, TVector<TString>* res) const;
};
-}
+} // namespace NJson
diff --git a/library/cpp/json/easy_parse/json_easy_parser_impl.h b/library/cpp/json/easy_parse/json_easy_parser_impl.h
index ec55d838b32..3106a11b414 100644
--- a/library/cpp/json/easy_parse/json_easy_parser_impl.h
+++ b/library/cpp/json/easy_parse/json_easy_parser_impl.h
@@ -9,7 +9,7 @@ namespace NJson {
MAP,
MAP_KEY
};
- }
+ } // namespace NImpl
template <class TStringType>
struct TPathElemImpl {
NImpl::EType Type;
@@ -37,4 +37,4 @@ namespace NJson {
};
typedef TPathElemImpl<TString> TPathElem;
-}
+} // namespace NJson
diff --git a/library/cpp/json/fast_sax/parser.h b/library/cpp/json/fast_sax/parser.h
index b5f031dd9eb..8f7cea7b7f0 100644
--- a/library/cpp/json/fast_sax/parser.h
+++ b/library/cpp/json/fast_sax/parser.h
@@ -10,4 +10,4 @@ namespace NJson {
TJsonCallbacks c(throwOnError);
return ReadJsonFast(in, &c);
}
-}
+} // namespace NJson
diff --git a/library/cpp/json/fuzzy_test/main.cpp b/library/cpp/json/fuzzy_test/main.cpp
index 29a53aac142..afa410cd6d9 100644
--- a/library/cpp/json/fuzzy_test/main.cpp
+++ b/library/cpp/json/fuzzy_test/main.cpp
@@ -10,20 +10,20 @@ extern "C" int LLVMFuzzerTestOneInput(const ui8* data, size_t size) {
NJson::TJsonValue value;
NJson::ReadJsonFastTree(json, &value, true);
} catch (...) {
- //Cout << json << " -> " << CurrentExceptionMessage() << Endl;
+ // Cout << json << " -> " << CurrentExceptionMessage() << Endl;
}
try {
NJson::TJsonCallbacks cb;
NJson::ReadJsonFast(json, &cb);
} catch (...) {
- //Cout << json << " -> " << CurrentExceptionMessage() << Endl;
+ // Cout << json << " -> " << CurrentExceptionMessage() << Endl;
}
try {
NJson::ValidateJson(json);
} catch (...) {
- //Cout << json << " -> " << CurrentExceptionMessage() << Endl;
+ // Cout << json << " -> " << CurrentExceptionMessage() << Endl;
}
return 0;
diff --git a/library/cpp/json/json_prettifier.cpp b/library/cpp/json/json_prettifier.cpp
index bb16aab44e5..a433e1887cc 100644
--- a/library/cpp/json/json_prettifier.cpp
+++ b/library/cpp/json/json_prettifier.cpp
@@ -26,8 +26,9 @@ namespace NJson {
}
void Hold(char c) {
- if (Dirty)
+ if (Dirty) {
Flush();
+ }
Last = c;
Dirty = true;
}
@@ -221,8 +222,9 @@ namespace NJson {
}
bool OnClose(char c) {
- if (!Level)
+ if (!Level) {
return false;
+ }
Level--;
@@ -237,16 +239,18 @@ namespace NJson {
}
bool OnCloseMap() override {
- if (!OnClose('{'))
+ if (!OnClose('{')) {
return false;
+ }
Out.Write("}");
AfterVal();
return true;
}
bool OnCloseArray() override {
- if (!OnClose('['))
+ if (!OnClose('[')) {
return false;
+ }
Out.Write("]");
AfterVal();
return true;
@@ -269,9 +273,10 @@ namespace NJson {
TString TJsonPrettifier::Prettify(TStringBuf in) const {
TStringStream s;
- if (Prettify(in, s))
+ if (Prettify(in, s)) {
return s.Str();
+ }
return TString();
}
-}
+} // namespace NJson
diff --git a/library/cpp/json/json_prettifier.h b/library/cpp/json/json_prettifier.h
index 27d611b0b43..d614db56c9a 100644
--- a/library/cpp/json/json_prettifier.h
+++ b/library/cpp/json/json_prettifier.h
@@ -55,4 +55,4 @@ namespace NJson {
return TJsonPrettifier::Compactifier(unquote, sq).Prettify(in);
}
-}
+} // namespace NJson
diff --git a/library/cpp/json/json_reader.cpp b/library/cpp/json/json_reader.cpp
index a1a9584481f..7a0803bde89 100644
--- a/library/cpp/json/json_reader.cpp
+++ b/library/cpp/json/json_reader.cpp
@@ -18,7 +18,7 @@ namespace NJson {
<< TStringBuf(", Code: ") << (int)result.Code()
<< TStringBuf(", Error: ") << GetParseError_En(result.Code());
}
- }
+ } // namespace
static const size_t DEFAULT_BUFFER_LEN = 65536;
@@ -101,8 +101,9 @@ namespace NJson {
bool TParserCallbacks::OnOpenArray() {
bool res = OpenComplexValue(JSON_ARRAY);
- if (res)
+ if (res) {
CurrentState = IN_ARRAY;
+ }
return res;
}
@@ -112,8 +113,9 @@ namespace NJson {
bool TParserCallbacks::OnOpenMap() {
bool res = OpenComplexValue(JSON_MAP);
- if (res)
+ if (res) {
CurrentState = IN_MAP;
+ }
return res;
}
@@ -134,7 +136,7 @@ namespace NJson {
}
bool TParserCallbacks::OnEnd() {
- if (NotClosedBracketIsError){
+ if (NotClosedBracketIsError) {
return ValuesStack.empty();
}
return true;
@@ -367,11 +369,10 @@ namespace NJson {
return reader.Parse<ConvertToRapidJsonFlags(currentFlags)>(is, handler);
}
-#define TRY_EXTRACT_FLAG(flag) \
- if (runtimeFlags & flag) { \
+#define TRY_EXTRACT_FLAG(flag) \
+ if (runtimeFlags & flag) { \
return ReadWithRuntimeFlags<TRapidJsonCompliantInputStream, THandler, currentFlags | flag>( \
- runtimeFlags ^ flag, reader, is, handler \
- ); \
+ runtimeFlags ^ flag, reader, is, handler); \
}
TRY_EXTRACT_FLAG(ReaderConfigFlags::NANINF);
@@ -390,7 +391,6 @@ namespace NJson {
rapidjson::Reader& reader,
TRapidJsonCompliantInputStream& is,
THandler& handler) {
-
// validate by default
ui8 flags = ReaderConfigFlags::VALIDATE;
@@ -437,7 +437,7 @@ namespace NJson {
bool ReadJsonTree(TRapidJsonCompliantInputStream& is, const TJsonReaderConfig* config, TJsonValue* out, bool throwOnError) {
out->SetType(NJson::JSON_NULL);
- TJsonValueBuilder handler(*out, { .MaxDepth = config->MaxDepth });
+ TJsonValueBuilder handler(*out, {.MaxDepth = config->MaxDepth});
return ReadJson(is, config, handler, throwOnError);
}
@@ -459,7 +459,7 @@ namespace NJson {
bool ReadJsonTreeImpl(TData* in, TJsonValue* out, bool throwOnError) {
return ReadJsonTreeImpl(in, false, out, throwOnError);
}
- } //namespace
+ } // namespace
bool ReadJsonTree(TStringBuf in, TJsonValue* out, bool throwOnError) {
return ReadJsonTreeImpl(&in, out, throwOnError);
@@ -580,7 +580,7 @@ namespace NJson {
return Impl.OnCloseArray();
}
};
- }
+ } // namespace
bool ReadJson(IInputStream* in, TJsonCallbacks* cbs) {
return ReadJson(in, false, cbs);
@@ -633,4 +633,4 @@ namespace NJson {
return out;
}
-}
+} // namespace NJson
diff --git a/library/cpp/json/json_reader.h b/library/cpp/json/json_reader.h
index 373a390085e..4880dfa7614 100644
--- a/library/cpp/json/json_reader.h
+++ b/library/cpp/json/json_reader.h
@@ -134,4 +134,4 @@ namespace NJson {
//// relaxed json, used in library/cpp/scheme
bool ReadJsonFastTree(TStringBuf in, TJsonValue* out, bool throwOnError = false, bool notClosedBracketIsError = false);
TJsonValue ReadJsonFastTree(TStringBuf in, bool notClosedBracketIsError = false);
-}
+} // namespace NJson
diff --git a/library/cpp/json/json_value.h b/library/cpp/json/json_value.h
index 47273f6b139..fb6f17d4500 100644
--- a/library/cpp/json/json_value.h
+++ b/library/cpp/json/json_value.h
@@ -1,3 +1,3 @@
#pragma once
-#include <library/cpp/json/writer/json_value.h> // IWYU pragma: export
+#include <library/cpp/json/writer/json_value.h> // IWYU pragma: export
diff --git a/library/cpp/json/json_writer.cpp b/library/cpp/json/json_writer.cpp
index 3d058bae360..33596ca4a27 100644
--- a/library/cpp/json/json_writer.cpp
+++ b/library/cpp/json/json_writer.cpp
@@ -69,8 +69,9 @@ namespace NJson {
}
void TJsonWriter::Write(const TStringBuf& value) {
- if (ValidateUtf8 && !IsUtf(value))
+ if (ValidateUtf8 && !IsUtf(value)) {
throw yexception() << "JSON writer: invalid UTF-8";
+ }
if (Buf.KeyExpected()) {
Buf.WriteKey(value);
} else {
@@ -112,7 +113,7 @@ namespace NJson {
return *a < *b;
}
};
- }
+ } // namespace
void TJsonWriter::Write(const TJsonValue* v) {
Buf.WriteJsonValue(v, SortKeys, FloatToStringMode, DoubleNDigits);
@@ -146,4 +147,4 @@ namespace NJson {
w.Flush();
}
-}
+} // namespace NJson
diff --git a/library/cpp/json/json_writer.h b/library/cpp/json/json_writer.h
index c7f5c9499a4..f7f380e545b 100644
--- a/library/cpp/json/json_writer.h
+++ b/library/cpp/json/json_writer.h
@@ -193,4 +193,4 @@ namespace NJson {
TString WriteJson(const TJsonValue*, bool formatOutput = true, bool sortkeys = false, bool validateUtf8 = false);
TString WriteJson(const TJsonValue&, bool formatOutput = true, bool sortkeys = false, bool validateUtf8 = false);
void WriteJson(IOutputStream*, const TJsonValue*, const TJsonWriterConfig& config);
-}
+} // namespace NJson
diff --git a/library/cpp/json/ordered_maps/json_ordered.cpp b/library/cpp/json/ordered_maps/json_ordered.cpp
index 438d4571a21..53da0101cab 100644
--- a/library/cpp/json/ordered_maps/json_ordered.cpp
+++ b/library/cpp/json/ordered_maps/json_ordered.cpp
@@ -25,7 +25,6 @@ namespace NJsonOrderedWriter {
StringStream.Reset(new TStringStream);
Stream = StringStream.Get();
}
-
Stack.reserve(64); // should be enough for most cases
StackPush(JE_OUTER_SPACE);
}
@@ -58,7 +57,8 @@ namespace NJsonOrderedWriter {
const EJsonEntity current = StackTop();
Stack.pop_back();
bool needMinusLevel = Stack.empty()
- ? false : StackTop() == EJsonEntity::JE_OBJECT;
+ ? false
+ : StackTop() == EJsonEntity::JE_OBJECT;
switch (current) {
case JE_OUTER_SPACE:
ythrow TError() << "JSON writer: stack empty";
@@ -86,13 +86,14 @@ namespace NJsonOrderedWriter {
}
void TBuf::PrintIndentation(bool closing, bool sublevel) {
- if (!IndentSpaces)
+ if (!IndentSpaces) {
return;
+ }
int substruct = Min<int>(int(sublevel) + 1, Stack.size());
const int indentation = IndentSpaces * (Stack.size() - substruct);
- if (!indentation && !closing)
+ if (!indentation && !closing) {
return;
-
+ }
PrintWhitespaces(Max(0, indentation), true);
}
@@ -106,7 +107,7 @@ namespace NJsonOrderedWriter {
const TStringBuf buffer = whitespacesTemplate.SubString(prependWithNewLine ? 0 : 1, count);
count -= buffer.size();
UnsafeWriteRawBytes(buffer);
- prependWithNewLine = false; // skip '\n' in subsequent writes
+ prependWithNewLine = false; // skip '\n' in subsequent writes
} while (count > 0);
}
@@ -288,7 +289,7 @@ namespace NJsonOrderedWriter {
}
}
};
- }
+ } // namespace
inline void TBuf::WriteBareString(const TStringBuf s, EHtmlEscapeMode hem) {
RawWriteChar('"');
@@ -326,10 +327,10 @@ namespace NJsonOrderedWriter {
RawWriteChar(hexDigits[(c & 0x0f)]);
}
-#define MATCH(sym, string) \
- case sym: \
- UnsafeWriteRawBytes(beg, cur - beg); \
- UnsafeWriteRawBytes(TStringBuf(string)); \
+#define MATCH(sym, string) \
+ case sym: \
+ UnsafeWriteRawBytes(beg, cur - beg); \
+ UnsafeWriteRawBytes(TStringBuf(string)); \
return true
inline bool TBuf::EscapedWriteChar(const char* beg, const char* cur, EHtmlEscapeMode hem) {
@@ -342,12 +343,11 @@ namespace NJsonOrderedWriter {
MATCH('>', "&gt;");
MATCH('&', "&amp;");
}
- //for other characters, we fall through to the non-HTML-escaped part
+ // for other characters, we fall through to the non-HTML-escaped part
}
-
- if (hem == HEM_RELAXED && c == '/')
+ if (hem == HEM_RELAXED && c == '/') {
return false;
-
+ }
if (hem != HEM_UNSAFE) {
switch (c) {
case '/':
@@ -363,7 +363,6 @@ namespace NJsonOrderedWriter {
}
// for other characters, fall through to the non-escaped part
}
-
switch (c) {
MATCH('"', "\\\"");
MATCH('\\', "\\\\");
@@ -378,7 +377,6 @@ namespace NJsonOrderedWriter {
WriteHexEscape(c);
return true;
}
-
return false;
}
@@ -413,8 +411,9 @@ namespace NJsonOrderedWriter {
case JSON_ARRAY: {
BeginList();
const TJsonValue::TArray& arr = v->GetArray();
- for (const auto& it : arr)
+ for (const auto& it : arr) {
WriteJsonValue(&it, sortKeys, mode, ndigits);
+ }
EndList();
break;
}
@@ -519,5 +518,4 @@ namespace NJsonOrderedWriter {
NeedNewline = from.NeedNewline;
Stack.swap(from.Stack);
}
-
-}
+} // namespace NJsonOrderedWriter
diff --git a/library/cpp/json/ordered_maps/json_ordered.h b/library/cpp/json/ordered_maps/json_ordered.h
index 3bdbb5a2200..db81673d5a1 100644
--- a/library/cpp/json/ordered_maps/json_ordered.h
+++ b/library/cpp/json/ordered_maps/json_ordered.h
@@ -10,10 +10,10 @@
namespace NJson::NOrderedJson {
class TJsonValue;
-}
+} // namespace NJson::NOrderedJson
namespace NJsonOrderedWriter {
- enum EJsonEntity : ui8 {
+ enum EJsonEntity: ui8 {
JE_OUTER_SPACE = 1,
JE_LIST,
JE_OBJECT,
@@ -39,7 +39,7 @@ namespace NJsonOrderedWriter {
TVector<EJsonEntity> Stack;
};
- class TBuf : TNonCopyable {
+ class TBuf: TNonCopyable {
public:
TBuf(EHtmlEscapeMode mode = HEM_DONT_ESCAPE_HTML, IOutputStream* stream = nullptr);
@@ -71,49 +71,49 @@ namespace NJsonOrderedWriter {
TBuf& EndObject();
/*** Indent the resulting JSON with spaces.
- * By default (spaces==0) no formatting is done. */
+ * By default (spaces==0) no formatting is done. */
TBuf& SetIndentSpaces(int spaces) {
IndentSpaces = spaces;
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) */
+ * so if WriteNanAsString is set, writer would write string
+ * intead of throwing exception (default case) */
TBuf& SetWriteNanAsString(bool writeNanAsString = true) {
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. */
+ * You may only call it if the `stream' parameter was NULL
+ * at construction time. */
const TString& Str() const;
/*** Dump and forget the string constructed so far.
- * You may only call it if the `stream' parameter was NULL
- * at construction time. */
+ * You may only call it if the `stream' parameter was NULL
+ * at construction time. */
void FlushTo(IOutputStream* stream);
/*** Write a literal string that represents a JSON value
- * (string, number, object, array, bool, or null).
- *
- * Example:
- * j.UnsafeWriteValue("[1, 2, 3, \"o'clock\", 4, \"o'clock rock\"]");
- *
- * As in all of the Unsafe* functions, no escaping is done. */
+ * (string, number, object, array, bool, or null).
+ *
+ * Example:
+ * 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 char* s, size_t len);
/*** When in the context of an object, write a literal string
- * that represents a key:value pair (or several pairs).
- *
- * Example:
- * j.BeginObject();
- * j.UnsafeWritePair("\"adam\": \"male\", \"eve\": \"female\"");
- * j.EndObject();
- *
- * As in all of the Unsafe* functions, no escaping is done. */
+ * that represents a key:value pair (or several pairs).
+ *
+ * Example:
+ * j.BeginObject();
+ * j.UnsafeWritePair("\"adam\": \"male\", \"eve\": \"female\"");
+ * j.EndObject();
+ *
+ * As in all of the Unsafe* functions, no escaping is done. */
TPairContext UnsafeWritePair(const TStringBuf& s);
/*** Copy the supplied string directly into the output stream. */
@@ -286,4 +286,4 @@ namespace NJsonOrderedWriter {
}
TString WrapJsonToCallback(const TBuf& buf, TStringBuf callback);
-}
+} // namespace NJsonOrderedWriter
diff --git a/library/cpp/json/ordered_maps/json_reader_ordered.cpp b/library/cpp/json/ordered_maps/json_reader_ordered.cpp
index babb4201978..217e8dd604b 100644
--- a/library/cpp/json/ordered_maps/json_reader_ordered.cpp
+++ b/library/cpp/json/ordered_maps/json_reader_ordered.cpp
@@ -18,7 +18,7 @@ namespace NJson::NOrderedJson {
<< TStringBuf(", Code: ") << (int)result.Code()
<< TStringBuf(", Error: ") << GetParseError_En(result.Code());
}
- }
+ } // namespace
static const size_t DEFAULT_BUFFER_LEN = 65536;
@@ -101,8 +101,9 @@ namespace NJson::NOrderedJson {
bool TParserCallbacks::OnOpenArray() {
bool res = OpenComplexValue(JSON_ARRAY);
- if (res)
+ if (res) {
CurrentState = IN_ARRAY;
+ }
return res;
}
@@ -112,8 +113,9 @@ namespace NJson::NOrderedJson {
bool TParserCallbacks::OnOpenMap() {
bool res = OpenComplexValue(JSON_MAP);
- if (res)
+ if (res) {
CurrentState = IN_MAP;
+ }
return res;
}
@@ -134,7 +136,7 @@ namespace NJson::NOrderedJson {
}
bool TParserCallbacks::OnEnd() {
- if (NotClosedBracketIsError){
+ if (NotClosedBracketIsError) {
return ValuesStack.empty();
}
return true;
@@ -367,11 +369,10 @@ namespace NJson::NOrderedJson {
return reader.Parse<ConvertToRapidJsonFlags(currentFlags)>(is, handler);
}
-#define TRY_EXTRACT_FLAG(flag) \
- if (runtimeFlags & flag) { \
+#define TRY_EXTRACT_FLAG(flag) \
+ if (runtimeFlags & flag) { \
return ReadWithRuntimeFlags<TRapidJsonCompliantInputStream, THandler, currentFlags | flag>( \
- runtimeFlags ^ flag, reader, is, handler \
- ); \
+ runtimeFlags ^ flag, reader, is, handler); \
}
TRY_EXTRACT_FLAG(ReaderConfigFlags::NANINF);
@@ -390,7 +391,6 @@ namespace NJson::NOrderedJson {
rapidjson::Reader& reader,
TRapidJsonCompliantInputStream& is,
THandler& handler) {
-
// validate by default
ui8 flags = ReaderConfigFlags::VALIDATE;
@@ -437,7 +437,7 @@ namespace NJson::NOrderedJson {
bool ReadJsonTree(TRapidJsonCompliantInputStream& is, const TJsonReaderConfig* config, TJsonValue* out, bool throwOnError) {
out->SetType(NJson::NOrderedJson::JSON_NULL);
- TJsonValueBuilder handler(*out, { .MaxDepth = config->MaxDepth });
+ TJsonValueBuilder handler(*out, {.MaxDepth = config->MaxDepth});
return ReadJson(is, config, handler, throwOnError);
}
@@ -459,7 +459,7 @@ namespace NJson::NOrderedJson {
bool ReadJsonTreeImpl(TData* in, TJsonValue* out, bool throwOnError) {
return ReadJsonTreeImpl(in, false, out, throwOnError);
}
- } //namespace
+ } // namespace
bool ReadJsonTree(TStringBuf in, TJsonValue* out, bool throwOnError) {
return ReadJsonTreeImpl(&in, out, throwOnError);
@@ -580,7 +580,7 @@ namespace NJson::NOrderedJson {
return Impl.OnCloseArray();
}
};
- }
+ } // namespace
bool ReadJson(IInputStream* in, TJsonCallbacks* cbs) {
return ReadJson(in, false, cbs);
@@ -633,4 +633,4 @@ namespace NJson::NOrderedJson {
return out;
}
-}
+} // namespace NJson::NOrderedJson
diff --git a/library/cpp/json/ordered_maps/json_reader_ordered.h b/library/cpp/json/ordered_maps/json_reader_ordered.h
index 019a7cb4b5e..f894b560158 100644
--- a/library/cpp/json/ordered_maps/json_reader_ordered.h
+++ b/library/cpp/json/ordered_maps/json_reader_ordered.h
@@ -134,4 +134,4 @@ namespace NJson::NOrderedJson {
//// relaxed json, used in library/cpp/scheme
bool ReadJsonFastTree(TStringBuf in, TJsonValue* out, bool throwOnError = false, bool notClosedBracketIsError = false);
TJsonValue ReadJsonFastTree(TStringBuf in, bool notClosedBracketIsError = false);
-}
+} // namespace NJson::NOrderedJson
diff --git a/library/cpp/json/ordered_maps/json_value_ordered.cpp b/library/cpp/json/ordered_maps/json_value_ordered.cpp
index b5e1a0dd7ff..121947677ca 100644
--- a/library/cpp/json/ordered_maps/json_value_ordered.cpp
+++ b/library/cpp/json/ordered_maps/json_value_ordered.cpp
@@ -20,25 +20,25 @@ AreJsonMapsEqual(const NJson::NOrderedJson::TJsonValue& lhs, const NJson::NOrder
Y_ABORT_UNLESS(lhs.GetType() == JSON_MAP, "lhs has not a JSON_MAP type.");
- if (rhs.GetType() != JSON_MAP)
+ if (rhs.GetType() != JSON_MAP) {
return false;
-
+ }
typedef TJsonValue::TMapType TMapType;
const TMapType& lhsMap = lhs.GetMap();
const TMapType& rhsMap = rhs.GetMap();
- if (lhsMap.size() != rhsMap.size())
+ if (lhsMap.size() != rhsMap.size()) {
return false;
-
+ }
for (const auto& lhsIt : lhsMap) {
TMapType::const_iterator rhsIt = rhsMap.find(lhsIt.first);
- if (rhsIt == rhsMap.end())
+ if (rhsIt == rhsMap.end()) {
return false;
-
- if (lhsIt.second != rhsIt->second)
+ }
+ if (lhsIt.second != rhsIt->second) {
return false;
+ }
}
-
return true;
}
@@ -48,22 +48,22 @@ AreJsonArraysEqual(const NJson::NOrderedJson::TJsonValue& lhs, const NJson::NOrd
Y_ABORT_UNLESS(lhs.GetType() == JSON_ARRAY, "lhs has not a JSON_ARRAY type.");
- if (rhs.GetType() != JSON_ARRAY)
+ if (rhs.GetType() != JSON_ARRAY) {
return false;
-
+ }
typedef TJsonValue::TArray TArray;
const TArray& lhsArray = lhs.GetArray();
const TArray& rhsArray = rhs.GetArray();
- if (lhsArray.size() != rhsArray.size())
+ if (lhsArray.size() != rhsArray.size()) {
return false;
-
+ }
for (TArray::const_iterator lhsIt = lhsArray.begin(), rhsIt = rhsArray.begin();
lhsIt != lhsArray.end(); ++lhsIt, ++rhsIt) {
- if (*lhsIt != *rhsIt)
+ if (*lhsIt != *rhsIt) {
return false;
+ }
}
-
return true;
}
@@ -149,16 +149,18 @@ namespace NJson::NOrderedJson {
}
TJsonValue& TJsonValue::operator=(const TJsonValue& val) {
- if (this == &val)
+ if (this == &val) {
return *this;
+ }
TJsonValue tmp(val);
tmp.Swap(*this);
return *this;
}
TJsonValue& TJsonValue::operator=(TJsonValue&& val) noexcept {
- if (this == &val)
+ if (this == &val) {
return *this;
+ }
TJsonValue tmp(std::move(val));
tmp.Swap(*this);
return *this;
@@ -224,12 +226,11 @@ namespace NJson::NOrderedJson {
}
TJsonValue& TJsonValue::SetType(const EJsonValueType type) {
- if (Type == type)
+ if (Type == type) {
return *this;
-
+ }
Clear();
Type = type;
-
switch (Type) {
case JSON_STRING:
new (&Value.String) TString();
@@ -248,7 +249,6 @@ namespace NJson::NOrderedJson {
case JSON_DOUBLE:
break;
}
-
return *this;
}
@@ -316,8 +316,9 @@ namespace NJson::NOrderedJson {
void TJsonValue::EraseValue(const TStringBuf key) {
if (IsMap()) {
TMapType::iterator it = Value.Map->find(key);
- if (it != Value.Map->end())
+ if (it != Value.Map->end()) {
Value.Map->erase(it);
+ }
}
}
@@ -356,8 +357,9 @@ namespace NJson::NOrderedJson {
TJsonValue& TJsonValue::operator[](const size_t idx) {
SetType(JSON_ARRAY);
- if (Value.Array->size() <= idx)
+ if (Value.Array->size() <= idx) {
Value.Array->resize(idx + 1);
+ }
return (*Value.Array)[idx];
}
@@ -373,21 +375,21 @@ namespace NJson::NOrderedJson {
const TJsonValue::TArray Array{};
const TJsonValue Value{};
};
- }
+ } // namespace
const TJsonValue& TJsonValue::operator[](const size_t idx) const noexcept {
const TJsonValue* ret = nullptr;
- if (GetValuePointer(idx, &ret))
+ if (GetValuePointer(idx, &ret)) {
return *ret;
-
+ }
return Singleton<TDefaultsHolder>()->Value;
}
const TJsonValue& TJsonValue::operator[](const TStringBuf& key) const noexcept {
const TJsonValue* ret = nullptr;
- if (GetValuePointer(key, &ret))
+ if (GetValuePointer(key, &ret)) {
return *ret;
-
+ }
return Singleton<TDefaultsHolder>()->Value;
}
@@ -396,9 +398,9 @@ namespace NJson::NOrderedJson {
}
long long TJsonValue::GetInteger() const {
- if (!IsInteger())
+ if (!IsInteger()) {
return 0;
-
+ }
switch (Type) {
case JSON_INTEGER:
return Value.Integer;
@@ -416,19 +418,16 @@ namespace NJson::NOrderedJson {
}
unsigned long long TJsonValue::GetUInteger() const {
- if (!IsUInteger())
+ if (!IsUInteger()) {
return 0;
-
+ }
switch (Type) {
case JSON_UINTEGER:
return Value.UInteger;
-
case JSON_INTEGER:
return Value.Integer;
-
case JSON_DOUBLE:
return Value.Double;
-
default:
Y_ASSERT(false && "Unexpected type.");
return 0;
@@ -436,19 +435,16 @@ namespace NJson::NOrderedJson {
}
double TJsonValue::GetDouble() const {
- if (!IsDouble())
+ if (!IsDouble()) {
return 0.0;
-
+ }
switch (Type) {
case JSON_DOUBLE:
return Value.Double;
-
case JSON_INTEGER:
return Value.Integer;
-
case JSON_UINTEGER:
return Value.UInteger;
-
default:
Y_ASSERT(false && "Unexpected type.");
return 0.0;
@@ -468,79 +464,79 @@ namespace NJson::NOrderedJson {
}
bool TJsonValue::GetBooleanSafe() const {
- if (Type != JSON_BOOLEAN)
+ if (Type != JSON_BOOLEAN) {
ythrow TJsonException() << "Not a boolean";
-
+ }
return Value.Boolean;
}
long long TJsonValue::GetIntegerSafe() const {
- if (!IsInteger())
+ if (!IsInteger()) {
ythrow TJsonException() << "Not an integer";
-
+ }
return GetInteger();
}
unsigned long long TJsonValue::GetUIntegerSafe() const {
- if (!IsUInteger())
+ if (!IsUInteger()) {
ythrow TJsonException() << "Not an unsigned integer";
-
+ }
return GetUInteger();
}
double TJsonValue::GetDoubleSafe() const {
- if (!IsDouble())
+ if (!IsDouble()) {
ythrow TJsonException() << "Not a double";
-
+ }
return GetDouble();
}
const TString& TJsonValue::GetStringSafe() const {
- if (Type != JSON_STRING)
+ if (Type != JSON_STRING) {
ythrow TJsonException() << "Not a string";
-
+ }
return Value.String;
}
bool TJsonValue::GetBooleanSafe(const bool defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetBooleanSafe();
}
long long TJsonValue::GetIntegerSafe(const long long defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetIntegerSafe();
}
unsigned long long TJsonValue::GetUIntegerSafe(const unsigned long long defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetUIntegerSafe();
}
double TJsonValue::GetDoubleSafe(const double defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetDoubleSafe();
}
TString TJsonValue::GetStringSafe(const TString& defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetStringSafe();
}
const TJsonValue::TMapType& TJsonValue::GetMapSafe() const {
- if (Type != JSON_MAP)
+ if (Type != JSON_MAP) {
ythrow TJsonException() << "Not a map";
-
+ }
return *Value.Map;
}
@@ -549,9 +545,9 @@ namespace NJson::NOrderedJson {
}
const TJsonValue::TArray& TJsonValue::GetArraySafe() const {
- if (Type != JSON_ARRAY)
+ if (Type != JSON_ARRAY) {
ythrow TJsonException() << "Not an array";
-
+ }
return *Value.Array;
}
@@ -721,73 +717,73 @@ namespace NJson::NOrderedJson {
}
bool TJsonValue::GetBoolean(bool* value) const noexcept {
- if (Type != JSON_BOOLEAN)
+ if (Type != JSON_BOOLEAN) {
return false;
-
+ }
*value = Value.Boolean;
return true;
}
bool TJsonValue::GetInteger(long long* value) const noexcept {
- if (!IsInteger())
+ if (!IsInteger()) {
return false;
-
+ }
*value = GetInteger();
return true;
}
bool TJsonValue::GetUInteger(unsigned long long* value) const noexcept {
- if (!IsUInteger())
+ if (!IsUInteger()) {
return false;
-
+ }
*value = GetUInteger();
return true;
}
bool TJsonValue::GetDouble(double* value) const noexcept {
- if (!IsDouble())
+ if (!IsDouble()) {
return false;
-
+ }
*value = GetDouble();
return true;
}
bool TJsonValue::GetString(TString* value) const {
- if (Type != JSON_STRING)
+ if (Type != JSON_STRING) {
return false;
-
+ }
*value = Value.String;
return true;
}
bool TJsonValue::GetMap(TJsonValue::TMapType* value) const {
- if (Type != JSON_MAP)
+ if (Type != JSON_MAP) {
return false;
-
+ }
*value = *Value.Map;
return true;
}
bool TJsonValue::GetArray(TJsonValue::TArray* value) const {
- if (Type != JSON_ARRAY)
+ if (Type != JSON_ARRAY) {
return false;
-
+ }
*value = *Value.Array;
return true;
}
bool TJsonValue::GetMapPointer(const TJsonValue::TMapType** value) const noexcept {
- if (Type != JSON_MAP)
+ if (Type != JSON_MAP) {
return false;
-
+ }
*value = Value.Map;
return true;
}
bool TJsonValue::GetArrayPointer(const TJsonValue::TArray** value) const noexcept {
- if (Type != JSON_ARRAY)
+ if (Type != JSON_ARRAY) {
return false;
-
+ }
*value = Value.Array;
return true;
}
@@ -845,13 +841,10 @@ namespace NJson::NOrderedJson {
switch (Type) {
case JSON_INTEGER:
return true;
-
case JSON_UINTEGER:
return (Value.UInteger <= static_cast<unsigned long long>(Max<long long>()));
-
case JSON_DOUBLE:
return ((long long)Value.Double == Value.Double);
-
default:
return false;
}
@@ -861,13 +854,10 @@ namespace NJson::NOrderedJson {
switch (Type) {
case JSON_UINTEGER:
return true;
-
case JSON_INTEGER:
return (Value.Integer >= 0);
-
case JSON_DOUBLE:
return ((unsigned long long)Value.Double == Value.Double);
-
default:
return false;
}
@@ -879,13 +869,10 @@ namespace NJson::NOrderedJson {
switch (Type) {
case JSON_DOUBLE:
return true;
-
case JSON_INTEGER:
return (1ll << std::numeric_limits<double>::digits) >= Abs(Value.Integer);
-
case JSON_UINTEGER:
return (1ull << std::numeric_limits<double>::digits) >= Value.UInteger;
-
default:
return false;
}
@@ -936,12 +923,10 @@ namespace NJson::NOrderedJson {
} else {
currentJson = CreateOrNullptr(currentJson, step, create_tag);
}
-
if (!currentJson) {
return nullptr;
}
}
-
return currentJson;
}
} // anonymous namespace
@@ -985,7 +970,6 @@ namespace NJson::NOrderedJson {
if (!callback.Do(path, parent, *this)) {
return;
}
-
if (Type == JSON_MAP) {
for (auto&& i : *Value.Map) {
i.second.DoScan(!!path ? TString::Join(path, ".", i.first) : i.first, this, callback);
@@ -1023,40 +1007,24 @@ namespace NJson::NOrderedJson {
bool TJsonValue::operator==(const TJsonValue& rhs) const {
switch (Type) {
- case JSON_UNDEFINED: {
+ case JSON_UNDEFINED:
return (rhs.GetType() == JSON_UNDEFINED);
- }
-
- case JSON_NULL: {
+ case JSON_NULL:
return rhs.IsNull();
- }
-
- case JSON_BOOLEAN: {
+ case JSON_BOOLEAN:
return (rhs.IsBoolean() && Value.Boolean == rhs.Value.Boolean);
- }
-
- case JSON_INTEGER: {
+ case JSON_INTEGER:
return (rhs.IsInteger() && GetInteger() == rhs.GetInteger());
- }
-
- case JSON_UINTEGER: {
+ case JSON_UINTEGER:
return (rhs.IsUInteger() && GetUInteger() == rhs.GetUInteger());
- }
-
- case JSON_STRING: {
+ case JSON_STRING:
return (rhs.IsString() && Value.String == rhs.Value.String);
- }
-
- case JSON_DOUBLE: {
+ case JSON_DOUBLE:
return (rhs.IsDouble() && fabs(GetDouble() - rhs.GetDouble()) <= FLT_EPSILON);
- }
-
case JSON_MAP:
return AreJsonMapsEqual(*this, rhs);
-
case JSON_ARRAY:
return AreJsonArraysEqual(*this, rhs);
-
default:
Y_ASSERT(false && "Unknown type.");
return false;
@@ -1071,7 +1039,6 @@ namespace NJson::NOrderedJson {
} else {
std::memcpy(&output.Value, &Value, sizeof(Value));
}
-
output.Type = Type;
Type = JSON_UNDEFINED;
}
@@ -1096,48 +1063,49 @@ namespace NJson::NOrderedJson {
bool GetMapPointer(const TJsonValue& jv, const size_t index, const TJsonValue::TMapType** value) {
const TJsonValue* v;
- if (!jv.GetValuePointer(index, &v) || !v->IsMap())
+ if (!jv.GetValuePointer(index, &v) || !v->IsMap()) {
return false;
-
+ }
*value = &v->GetMap();
return true;
}
bool GetArrayPointer(const TJsonValue& jv, const size_t index, const TJsonValue::TArray** value) {
const TJsonValue* v;
- if (!jv.GetValuePointer(index, &v) || !v->IsArray())
+ if (!jv.GetValuePointer(index, &v) || !v->IsArray()) {
return false;
-
+ }
*value = &v->GetArray();
return true;
}
bool GetMapPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TMapType** value) {
const TJsonValue* v;
- if (!jv.GetValuePointer(key, &v) || !v->IsMap())
+ if (!jv.GetValuePointer(key, &v) || !v->IsMap()) {
return false;
-
+ }
*value = &v->GetMap();
return true;
}
bool GetArrayPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TArray** value) {
const TJsonValue* v;
- if (!jv.GetValuePointer(key, &v) || !v->IsArray())
+ if (!jv.GetValuePointer(key, &v) || !v->IsArray()) {
return false;
-
+ }
*value = &v->GetArray();
return true;
}
void TJsonValue::BackChecks() const {
- if (Type != JSON_ARRAY)
+ if (Type != JSON_ARRAY) {
ythrow TJsonException() << "Not an array";
-
- if (Value.Array->empty())
+ }
+ if (Value.Array->empty()) {
ythrow TJsonException() << "Get back on empty array";
+ }
}
-}
+} // namespace NJson::NOrderedJson
template <>
void Out<NJson::NOrderedJson::TJsonValue>(IOutputStream& out, const NJson::NOrderedJson::TJsonValue& v) {
diff --git a/library/cpp/json/ordered_maps/json_value_ordered.h b/library/cpp/json/ordered_maps/json_value_ordered.h
index 305d600e402..0cab2d79ee3 100644
--- a/library/cpp/json/ordered_maps/json_value_ordered.h
+++ b/library/cpp/json/ordered_maps/json_value_ordered.h
@@ -124,7 +124,7 @@ namespace NJson::NOrderedJson {
const TMapType& GetMap() const Y_LIFETIME_BOUND;
const TArray& GetArray() const Y_LIFETIME_BOUND;
- //throwing TJsonException possible
+ // throwing TJsonException possible
bool GetBooleanSafe() const;
long long GetIntegerSafe() const;
unsigned long long GetUIntegerSafe() const;
@@ -279,7 +279,8 @@ namespace NJson::NOrderedJson {
public:
TJsonMap()
: TJsonValue(NJson::NOrderedJson::JSON_MAP)
- {}
+ {
+ }
TJsonMap(const std::initializer_list<std::pair<TString, TJsonValue>>& list)
: TJsonValue(NJson::NOrderedJson::JSON_MAP)
@@ -298,7 +299,8 @@ namespace NJson::NOrderedJson {
public:
TJsonArray()
: TJsonValue(NJson::NOrderedJson::JSON_ARRAY)
- {}
+ {
+ }
TJsonArray(const std::initializer_list<TJsonValue>& list)
: TJsonValue(NJson::NOrderedJson::JSON_ARRAY)
@@ -306,4 +308,4 @@ namespace NJson::NOrderedJson {
GetArraySafe() = TJsonValue::TArray(list);
}
};
-}
+} // namespace NJson::NOrderedJson
diff --git a/library/cpp/json/ordered_maps/json_writer_ordered.cpp b/library/cpp/json/ordered_maps/json_writer_ordered.cpp
index 39f63a3e567..2e44a43376b 100644
--- a/library/cpp/json/ordered_maps/json_writer_ordered.cpp
+++ b/library/cpp/json/ordered_maps/json_writer_ordered.cpp
@@ -69,8 +69,9 @@ namespace NJson::NOrderedJson {
}
void TJsonWriter::Write(const TStringBuf& value) {
- if (ValidateUtf8 && !IsUtf(value))
+ if (ValidateUtf8 && !IsUtf(value)) {
throw yexception() << "JSON writer: invalid UTF-8";
+ }
if (Buf.KeyExpected()) {
Buf.WriteKey(value);
} else {
@@ -112,7 +113,7 @@ namespace NJson::NOrderedJson {
return *a < *b;
}
};
- }
+ } // namespace
void TJsonWriter::Write(const TJsonValue* v) {
Buf.WriteJsonValue(v, SortKeys, FloatToStringMode, DoubleNDigits);
@@ -146,4 +147,4 @@ namespace NJson::NOrderedJson {
w.Flush();
}
-}
+} // namespace NJson::NOrderedJson
diff --git a/library/cpp/json/ordered_maps/json_writer_ordered.h b/library/cpp/json/ordered_maps/json_writer_ordered.h
index cfb2e30bd49..f9c729665e9 100644
--- a/library/cpp/json/ordered_maps/json_writer_ordered.h
+++ b/library/cpp/json/ordered_maps/json_writer_ordered.h
@@ -191,4 +191,4 @@ namespace NJson::NOrderedJson {
TString WriteJson(const TJsonValue*, bool formatOutput = true, bool sortkeys = false, bool validateUtf8 = false);
TString WriteJson(const TJsonValue&, bool formatOutput = true, bool sortkeys = false, bool validateUtf8 = false);
void WriteJson(IOutputStream*, const TJsonValue*, const TJsonWriterConfig& config);
-}
+} // namespace NJson::NOrderedJson
diff --git a/library/cpp/json/ordered_maps/ut/json_ordered_ut.cpp b/library/cpp/json/ordered_maps/ut/json_ordered_ut.cpp
index 93d81485660..0312f0b6960 100644
--- a/library/cpp/json/ordered_maps/ut/json_ordered_ut.cpp
+++ b/library/cpp/json/ordered_maps/ut/json_ordered_ut.cpp
@@ -265,4 +265,4 @@ Y_UNIT_TEST_SUITE(JsonWriter) {
UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"({"\u003C\u003E&":"Ololo","<>&":"Ololo2"})");
}
}
-}
+} // Y_UNIT_TEST_SUITE(JsonWriter)
diff --git a/library/cpp/json/ordered_maps/ut/json_reader_fast_ordered_ut.cpp b/library/cpp/json/ordered_maps/ut/json_reader_fast_ordered_ut.cpp
index de9702f8775..8dc7f1e26d0 100644
--- a/library/cpp/json/ordered_maps/ut/json_reader_fast_ordered_ut.cpp
+++ b/library/cpp/json/ordered_maps/ut/json_reader_fast_ordered_ut.cpp
@@ -86,7 +86,7 @@ namespace NJson::NOrderedJson {
using TEvents = TVector<TEvent>;
- struct TTestHandler : TJsonCallbacks {
+ struct TTestHandler: TJsonCallbacks {
TEvents Events;
bool OnOpenMap() override {
@@ -167,8 +167,8 @@ namespace NJson::NOrderedJson {
}
}
};
- }
-}
+ } // namespace NTest
+} // namespace NJson::NOrderedJson
class TFastJsonTest: public TTestBase {
UNIT_TEST_SUITE(TFastJsonTest)
@@ -263,14 +263,14 @@ public:
DoTestParse<true>("{}", 2, E_DICT_OPEN, E_DICT_CLOSE);
DoTestParse<true>("{ a : x, b : [ c, d, ] }", 9, E_DICT_OPEN, E_KEY, "a", E_STR, "x", E_KEY, "b", E_ARR_OPEN, E_STR, "c", E_STR, "d", E_ARR_CLOSE, E_DICT_CLOSE);
DoTestParse<false>("{ a : x, b : [ c, d,, ] }", 8, E_DICT_OPEN, E_KEY, "a", E_STR, "x", E_KEY, "b", E_ARR_OPEN, E_STR, "c", E_STR, "d", E_ERROR, "invalid syntax at token: ','");
- // DoTestParse<false>("{ a : x : y }", 4, E_DICT_OPEN
- // , E_KEY, "a", E_STR, "x"
- // , E_ERROR
- // , ":");
- // DoTestParse<false>("{queries:{ref:[]},{nonref:[]}}", 8, E_DICT_OPEN
- // , E_KEY, "queries", E_DICT_OPEN
- // , E_KEY, "ref", E_ARR_OPEN, E_ARR_CLOSE
- // , E_DICT_CLOSE, E_ERROR, "");
+ // DoTestParse<false>("{ a : x : y }", 4, E_DICT_OPEN
+ // , E_KEY, "a", E_STR, "x"
+ // , E_ERROR
+ // , ":");
+ // DoTestParse<false>("{queries:{ref:[]},{nonref:[]}}", 8, E_DICT_OPEN
+ // , E_KEY, "queries", E_DICT_OPEN
+ // , E_KEY, "ref", E_ARR_OPEN, E_ARR_CLOSE
+ // , E_DICT_CLOSE, E_ERROR, "");
DoTestParse<true>("'100x00'", 1, E_STR, "100x00");
DoTestParse<true>("-1", 1, E_INT, -1);
DoTestParse<true>("-9223372036854775808", 1, E_LONG_LONG, (long long)Min<i64>());
diff --git a/library/cpp/json/ordered_maps/ut/json_reader_nan_ordered_ut.cpp b/library/cpp/json/ordered_maps/ut/json_reader_nan_ordered_ut.cpp
index 71c3cc2e7a6..3bec567509e 100644
--- a/library/cpp/json/ordered_maps/ut/json_reader_nan_ordered_ut.cpp
+++ b/library/cpp/json/ordered_maps/ut/json_reader_nan_ordered_ut.cpp
@@ -5,9 +5,9 @@ using namespace NJson::NOrderedJson;
namespace {
-constexpr TStringBuf JSON_NAN_TEST = "{ \"Value1\": 0.0, \"Value2\": 1, \"Value3\": NaN }";
+ constexpr TStringBuf JSON_NAN_TEST = "{ \"Value1\": 0.0, \"Value2\": 1, \"Value3\": NaN }";
-}
+} // namespace
Y_UNIT_TEST_SUITE(TJsonReaderNanTest) {
Y_UNIT_TEST(WithoutNanTest) {
@@ -15,7 +15,6 @@ Y_UNIT_TEST_SUITE(TJsonReaderNanTest) {
TJsonValue out;
// This read will fail
UNIT_ASSERT(!ReadJsonTree(JSON_NAN_TEST, &cfg, &out, /* throwOnError */ false));
-
}
Y_UNIT_TEST(WithNanTest) {
TJsonReaderConfig cfg;
@@ -25,5 +24,4 @@ Y_UNIT_TEST_SUITE(TJsonReaderNanTest) {
// This read will ok
UNIT_ASSERT(ReadJsonTree(JSON_NAN_TEST, &cfg, &out, /* throwOnError */ false));
}
-}
-
+} // Y_UNIT_TEST_SUITE(TJsonReaderNanTest)
diff --git a/library/cpp/json/ordered_maps/ut/json_reader_ordered_ut.cpp b/library/cpp/json/ordered_maps/ut/json_reader_ordered_ut.cpp
index bd317cf7a6f..5c4c2ce36ad 100644
--- a/library/cpp/json/ordered_maps/ut/json_reader_ordered_ut.cpp
+++ b/library/cpp/json/ordered_maps/ut/json_reader_ordered_ut.cpp
@@ -374,7 +374,7 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 0.0);
UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), static_cast<double>(Max<ui64>()));
} // Max<ui64>()
- } // TJsonDoubleTest
+ } // TJsonDoubleTest
Y_UNIT_TEST(TJsonInvalidTest) {
{
@@ -473,12 +473,10 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
UNIT_ASSERT(!ReadJsonTree(&jsonStream, &config, &v));
}
}
-}
-
+} // Y_UNIT_TEST_SUITE(TJsonReaderTest)
static const TString YANDEX_STREAMING_JSON("{\"a\":1}//d{\"b\":2}");
-
Y_UNIT_TEST_SUITE(TCompareReadJsonFast) {
Y_UNIT_TEST(NoEndl) {
NJson::NOrderedJson::TJsonValue parsed;
@@ -504,4 +502,4 @@ Y_UNIT_TEST_SUITE(TCompareReadJsonFast) {
bool fast_success = NJson::NOrderedJson::ReadJsonFastTree(streamingJson, &parsed, false);
UNIT_ASSERT(success != fast_success);
}
-}
+} // Y_UNIT_TEST_SUITE(TCompareReadJsonFast)
diff --git a/library/cpp/json/ordered_maps/ut/json_value_ordered_ut.cpp b/library/cpp/json/ordered_maps/ut/json_value_ordered_ut.cpp
index d9c798410bc..20428da5c4a 100644
--- a/library/cpp/json/ordered_maps/ut/json_value_ordered_ut.cpp
+++ b/library/cpp/json/ordered_maps/ut/json_value_ordered_ut.cpp
@@ -8,10 +8,10 @@ using namespace NJson::NOrderedJson;
Y_UNIT_TEST_SUITE(TJsonValueTest) {
Y_UNIT_TEST(Equal) {
- UNIT_ASSERT(1 == TJsonValue(1));
- UNIT_ASSERT(TJsonValue(1) == 1);
- UNIT_ASSERT(2 != TJsonValue(1));
- UNIT_ASSERT(TJsonValue(1) != 2);
+ UNIT_ASSERT(1 == TJsonValue(1));
+ UNIT_ASSERT(TJsonValue(1) == 1);
+ UNIT_ASSERT(2 != TJsonValue(1));
+ UNIT_ASSERT(TJsonValue(1) != 2);
}
Y_UNIT_TEST(UndefTest) {
@@ -175,14 +175,17 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
const int NUM_KEYS = 1000;
TJsonValue lhs;
- for (int i = 0; i < NUM_KEYS; ++i)
+ for (int i = 0; i < NUM_KEYS; ++i) {
lhs.InsertValue(ToString(i), i);
+ }
TJsonValue rhs;
- for (int i = 0; i < NUM_KEYS; i += 2)
+ for (int i = 0; i < NUM_KEYS; i += 2) {
rhs.InsertValue(ToString(i), i);
- for (int i = 1; i < NUM_KEYS; i += 2)
+ }
+ for (int i = 1; i < NUM_KEYS; i += 2) {
rhs.InsertValue(ToString(i), i);
+ }
UNIT_ASSERT(lhs == rhs);
UNIT_ASSERT(rhs == lhs);
@@ -728,8 +731,7 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
NJson::TJsonValue(NJson::JSON_ARRAY),
NJson::TJsonValue(NJson::JSON_MAP),
nonEmptyArray,
- nonEmptyMap
- };
+ nonEmptyMap};
for (const auto& val : values) {
TJsonValue ordered(val);
@@ -877,8 +879,7 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
TJsonValue(3.14),
TJsonValue("test string"),
TJsonValue(JSON_ARRAY),
- TJsonValue(JSON_MAP)
- };
+ TJsonValue(JSON_MAP)};
for (auto& original : values) {
TStringStream ss;
@@ -891,8 +892,7 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
original.IsBoolean() || original.IsInteger() ||
original.IsUInteger() || original.IsDouble() ||
original.IsString() || original.IsNull() ||
- !original.IsDefined()
- ) {
+ !original.IsDefined()) {
UNIT_ASSERT(loaded == original);
} else if (original.IsMap()) {
UNIT_ASSERT(loaded.IsMap());
@@ -944,4 +944,4 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
UNIT_ASSERT_VALUES_EQUAL(it->second.GetIntegerRobust(), i);
}
}
-} // TJsonValueTest
+} // Y_UNIT_TEST_SUITE(TJsonValueTest)
diff --git a/library/cpp/json/ordered_maps/ut/json_writer_ordered_ut.cpp b/library/cpp/json/ordered_maps/ut/json_writer_ordered_ut.cpp
index 1e6213668fc..70cde050d61 100644
--- a/library/cpp/json/ordered_maps/ut/json_writer_ordered_ut.cpp
+++ b/library/cpp/json/ordered_maps/ut/json_writer_ordered_ut.cpp
@@ -120,7 +120,7 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) {
WriteJson(&out, &v);
UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
} // 18446744073709551615
- } // SimpleUnsignedIntegerWriteTest
+ } // SimpleUnsignedIntegerWriteTest
Y_UNIT_TEST(WriteOptionalTest) {
{
@@ -225,4 +225,4 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) {
UNIT_ASSERT_VALUES_EQUAL(actual, expected);
}
}
-}
+} // Y_UNIT_TEST_SUITE(TJsonWriterTest)
diff --git a/library/cpp/json/rapidjson_helpers.h b/library/cpp/json/rapidjson_helpers.h
index aeb96ff6703..8fb1741f5e2 100644
--- a/library/cpp/json/rapidjson_helpers.h
+++ b/library/cpp/json/rapidjson_helpers.h
@@ -26,7 +26,7 @@ namespace NJson {
}
};
- struct TInputStreamWrapper : TReadOnlyStreamBase {
+ struct TInputStreamWrapper: TReadOnlyStreamBase {
Ch Peek() const {
if (!Eof) {
if (Pos >= Sz) {
@@ -77,7 +77,7 @@ namespace NJson {
size_t Count;
};
- struct TStringBufStreamWrapper : TReadOnlyStreamBase {
+ struct TStringBufStreamWrapper: TReadOnlyStreamBase {
Ch Peek() const {
return Pos < Data.size() ? Data[Pos] : 0;
}
@@ -101,4 +101,4 @@ namespace NJson {
TStringBuf Data;
size_t Pos;
};
-}
+} // namespace NJson
diff --git a/library/cpp/json/ut/json_prettifier_ut.cpp b/library/cpp/json/ut/json_prettifier_ut.cpp
index ae5f8dd81a4..03a3b09ee23 100644
--- a/library/cpp/json/ut/json_prettifier_ut.cpp
+++ b/library/cpp/json/ut/json_prettifier_ut.cpp
@@ -201,4 +201,4 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) {
true),
"{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}");
}
-}
+} // Y_UNIT_TEST_SUITE(JsonPrettifier)
diff --git a/library/cpp/json/ut/json_reader_fast_ut.cpp b/library/cpp/json/ut/json_reader_fast_ut.cpp
index 60dffc91c73..7ec516bd838 100644
--- a/library/cpp/json/ut/json_reader_fast_ut.cpp
+++ b/library/cpp/json/ut/json_reader_fast_ut.cpp
@@ -86,7 +86,7 @@ namespace NJson {
using TEvents = TVector<TEvent>;
- struct TTestHandler : TJsonCallbacks {
+ struct TTestHandler: TJsonCallbacks {
TEvents Events;
bool OnOpenMap() override {
@@ -167,8 +167,8 @@ namespace NJson {
}
}
};
- }
-}
+ } // namespace NTest
+} // namespace NJson
class TFastJsonTest: public TTestBase {
UNIT_TEST_SUITE(TFastJsonTest)
@@ -263,14 +263,14 @@ public:
DoTestParse<true>("{}", 2, E_DICT_OPEN, E_DICT_CLOSE);
DoTestParse<true>("{ a : x, b : [ c, d, ] }", 9, E_DICT_OPEN, E_KEY, "a", E_STR, "x", E_KEY, "b", E_ARR_OPEN, E_STR, "c", E_STR, "d", E_ARR_CLOSE, E_DICT_CLOSE);
DoTestParse<false>("{ a : x, b : [ c, d,, ] }", 8, E_DICT_OPEN, E_KEY, "a", E_STR, "x", E_KEY, "b", E_ARR_OPEN, E_STR, "c", E_STR, "d", E_ERROR, "invalid syntax at token: ','");
- // DoTestParse<false>("{ a : x : y }", 4, E_DICT_OPEN
- // , E_KEY, "a", E_STR, "x"
- // , E_ERROR
- // , ":");
- // DoTestParse<false>("{queries:{ref:[]},{nonref:[]}}", 8, E_DICT_OPEN
- // , E_KEY, "queries", E_DICT_OPEN
- // , E_KEY, "ref", E_ARR_OPEN, E_ARR_CLOSE
- // , E_DICT_CLOSE, E_ERROR, "");
+ // DoTestParse<false>("{ a : x : y }", 4, E_DICT_OPEN
+ // , E_KEY, "a", E_STR, "x"
+ // , E_ERROR
+ // , ":");
+ // DoTestParse<false>("{queries:{ref:[]},{nonref:[]}}", 8, E_DICT_OPEN
+ // , E_KEY, "queries", E_DICT_OPEN
+ // , E_KEY, "ref", E_ARR_OPEN, E_ARR_CLOSE
+ // , E_DICT_CLOSE, E_ERROR, "");
DoTestParse<true>("'100x00'", 1, E_STR, "100x00");
DoTestParse<true>("-1", 1, E_INT, -1);
DoTestParse<true>("-9223372036854775808", 1, E_LONG_LONG, (long long)Min<i64>());
diff --git a/library/cpp/json/ut/json_reader_nan_ut.cpp b/library/cpp/json/ut/json_reader_nan_ut.cpp
index fdd66249eb2..2b1582b77f0 100644
--- a/library/cpp/json/ut/json_reader_nan_ut.cpp
+++ b/library/cpp/json/ut/json_reader_nan_ut.cpp
@@ -5,9 +5,9 @@ using namespace NJson;
namespace {
-constexpr TStringBuf JSON_NAN_TEST = "{ \"Value1\": 0.0, \"Value2\": 1, \"Value3\": NaN }";
+ constexpr TStringBuf JSON_NAN_TEST = "{ \"Value1\": 0.0, \"Value2\": 1, \"Value3\": NaN }";
-}
+} // namespace
Y_UNIT_TEST_SUITE(TJsonReaderNanTest) {
Y_UNIT_TEST(WithoutNanTest) {
@@ -15,7 +15,6 @@ Y_UNIT_TEST_SUITE(TJsonReaderNanTest) {
TJsonValue out;
// This read will fail
UNIT_ASSERT(!ReadJsonTree(JSON_NAN_TEST, &cfg, &out, /* throwOnError */ false));
-
}
Y_UNIT_TEST(WithNanTest) {
TJsonReaderConfig cfg;
@@ -25,5 +24,4 @@ Y_UNIT_TEST_SUITE(TJsonReaderNanTest) {
// This read will ok
UNIT_ASSERT(ReadJsonTree(JSON_NAN_TEST, &cfg, &out, /* throwOnError */ false));
}
-}
-
+} // Y_UNIT_TEST_SUITE(TJsonReaderNanTest)
diff --git a/library/cpp/json/ut/json_reader_ut.cpp b/library/cpp/json/ut/json_reader_ut.cpp
index 07de6a7ac3c..376bd2a17e5 100644
--- a/library/cpp/json/ut/json_reader_ut.cpp
+++ b/library/cpp/json/ut/json_reader_ut.cpp
@@ -374,7 +374,7 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 0.0);
UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), static_cast<double>(Max<ui64>()));
} // Max<ui64>()
- } // TJsonDoubleTest
+ } // TJsonDoubleTest
Y_UNIT_TEST(TJsonInvalidTest) {
{
@@ -473,12 +473,10 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
UNIT_ASSERT(!ReadJsonTree(&jsonStream, &config, &v));
}
}
-}
-
+} // Y_UNIT_TEST_SUITE(TJsonReaderTest)
static const TString YANDEX_STREAMING_JSON("{\"a\":1}//d{\"b\":2}");
-
Y_UNIT_TEST_SUITE(TCompareReadJsonFast) {
Y_UNIT_TEST(NoEndl) {
NJson::TJsonValue parsed;
@@ -504,4 +502,4 @@ Y_UNIT_TEST_SUITE(TCompareReadJsonFast) {
bool fast_success = NJson::ReadJsonFastTree(streamingJson, &parsed, false);
UNIT_ASSERT(success != fast_success);
}
-}
+} // Y_UNIT_TEST_SUITE(TCompareReadJsonFast)
diff --git a/library/cpp/json/ut/json_saveload_ut.cpp b/library/cpp/json/ut/json_saveload_ut.cpp
index b480a80fe4c..979469dfda0 100644
--- a/library/cpp/json/ut/json_saveload_ut.cpp
+++ b/library/cpp/json/ut/json_saveload_ut.cpp
@@ -7,7 +7,6 @@
Y_UNIT_TEST_SUITE(JsonSaveLoad) {
Y_UNIT_TEST(Serialize) {
-
NJson::TJsonValue expected;
expected["ui64"] = ui64(1);
@@ -33,4 +32,4 @@ Y_UNIT_TEST_SUITE(JsonSaveLoad) {
UNIT_ASSERT_EQUAL_C(expected, load, "expected: " << expected << ", got: " << load);
}
-}
+} // Y_UNIT_TEST_SUITE(JsonSaveLoad)
diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp
index ca11d34dad9..4dcee17230a 100644
--- a/library/cpp/json/ut/json_writer_ut.cpp
+++ b/library/cpp/json/ut/json_writer_ut.cpp
@@ -120,7 +120,7 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) {
WriteJson(&out, &v);
UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
} // 18446744073709551615
- } // SimpleUnsignedIntegerWriteTest
+ } // SimpleUnsignedIntegerWriteTest
Y_UNIT_TEST(WriteOptionalTest) {
{
@@ -225,4 +225,4 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) {
UNIT_ASSERT_VALUES_EQUAL(actual, expected);
}
}
-}
+} // Y_UNIT_TEST_SUITE(TJsonWriterTest)
diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp
index a732e470521..0b2a6e1b47b 100644
--- a/library/cpp/json/writer/json.cpp
+++ b/library/cpp/json/writer/json.cpp
@@ -25,7 +25,6 @@ namespace NJsonWriter {
StringStream.Reset(new TStringStream);
Stream = StringStream.Get();
}
-
Stack.reserve(64); // should be enough for most cases
StackPush(JE_OUTER_SPACE);
}
@@ -84,12 +83,13 @@ namespace NJsonWriter {
}
void TBuf::PrintIndentation(bool closing) {
- if (!IndentSpaces)
+ if (!IndentSpaces) {
return;
+ }
const int indentation = IndentSpaces * (Stack.size() - 1);
- if (!indentation && !closing)
+ if (!indentation && !closing) {
return;
-
+ }
PrintWhitespaces(Max(0, indentation), true);
}
@@ -103,7 +103,7 @@ namespace NJsonWriter {
const TStringBuf buffer = whitespacesTemplate.SubString(prependWithNewLine ? 0 : 1, count);
count -= buffer.size();
UnsafeWriteRawBytes(buffer);
- prependWithNewLine = false; // skip '\n' in subsequent writes
+ prependWithNewLine = false; // skip '\n' in subsequent writes
} while (count > 0);
}
@@ -282,7 +282,7 @@ namespace NJsonWriter {
}
}
};
- }
+ } // namespace
inline void TBuf::WriteBareString(const TStringBuf s, EHtmlEscapeMode hem) {
RawWriteChar('"');
@@ -320,10 +320,10 @@ namespace NJsonWriter {
RawWriteChar(hexDigits[(c & 0x0f)]);
}
-#define MATCH(sym, string) \
- case sym: \
- UnsafeWriteRawBytes(beg, cur - beg); \
- UnsafeWriteRawBytes(TStringBuf(string)); \
+#define MATCH(sym, string) \
+ case sym: \
+ UnsafeWriteRawBytes(beg, cur - beg); \
+ UnsafeWriteRawBytes(TStringBuf(string)); \
return true
inline bool TBuf::EscapedWriteChar(const char* beg, const char* cur, EHtmlEscapeMode hem) {
@@ -336,12 +336,11 @@ namespace NJsonWriter {
MATCH('>', "&gt;");
MATCH('&', "&amp;");
}
- //for other characters, we fall through to the non-HTML-escaped part
+ // for other characters, we fall through to the non-HTML-escaped part
}
-
- if (hem == HEM_RELAXED && c == '/')
+ if (hem == HEM_RELAXED && c == '/') {
return false;
-
+ }
if (hem != HEM_UNSAFE) {
switch (c) {
case '/':
@@ -357,7 +356,6 @@ namespace NJsonWriter {
}
// for other characters, fall through to the non-escaped part
}
-
switch (c) {
MATCH('"', "\\\"");
MATCH('\\', "\\\\");
@@ -372,7 +370,6 @@ namespace NJsonWriter {
WriteHexEscape(c);
return true;
}
-
return false;
}
@@ -407,8 +404,9 @@ namespace NJsonWriter {
case JSON_ARRAY: {
BeginList();
const TJsonValue::TArray& arr = v->GetArray();
- for (const auto& it : arr)
+ for (const auto& it : arr) {
WriteJsonValue(&it, sortKeys, mode, ndigits);
+ }
EndList();
break;
}
@@ -513,5 +511,4 @@ namespace NJsonWriter {
NeedNewline = from.NeedNewline;
Stack.swap(from.Stack);
}
-
-}
+} // namespace NJsonWriter
diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h
index 0aae2531b94..4a6e0af8129 100644
--- a/library/cpp/json/writer/json.h
+++ b/library/cpp/json/writer/json.h
@@ -10,10 +10,10 @@
namespace NJson {
class TJsonValue;
-}
+} // namespace NJson
namespace NJsonWriter {
- enum EJsonEntity : ui8 {
+ enum EJsonEntity: ui8 {
JE_OUTER_SPACE = 1,
JE_LIST,
JE_OBJECT,
@@ -39,7 +39,7 @@ namespace NJsonWriter {
TVector<EJsonEntity> Stack;
};
- class TBuf : TNonCopyable {
+ class TBuf: TNonCopyable {
public:
TBuf(EHtmlEscapeMode mode = HEM_DONT_ESCAPE_HTML, IOutputStream* stream = nullptr);
@@ -71,49 +71,49 @@ namespace NJsonWriter {
TBuf& EndObject();
/*** Indent the resulting JSON with spaces.
- * By default (spaces==0) no formatting is done. */
+ * By default (spaces==0) no formatting is done. */
TBuf& SetIndentSpaces(int spaces) {
IndentSpaces = spaces;
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) */
+ * so if WriteNanAsString is set, writer would write string
+ * intead of throwing exception (default case) */
TBuf& SetWriteNanAsString(bool writeNanAsString = true) {
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. */
+ * You may only call it if the `stream' parameter was NULL
+ * at construction time. */
const TString& Str() const;
/*** Dump and forget the string constructed so far.
- * You may only call it if the `stream' parameter was NULL
- * at construction time. */
+ * You may only call it if the `stream' parameter was NULL
+ * at construction time. */
void FlushTo(IOutputStream* stream);
/*** Write a literal string that represents a JSON value
- * (string, number, object, array, bool, or null).
- *
- * Example:
- * j.UnsafeWriteValue("[1, 2, 3, \"o'clock\", 4, \"o'clock rock\"]");
- *
- * As in all of the Unsafe* functions, no escaping is done. */
+ * (string, number, object, array, bool, or null).
+ *
+ * Example:
+ * 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 char* s, size_t len);
/*** When in the context of an object, write a literal string
- * that represents a key:value pair (or several pairs).
- *
- * Example:
- * j.BeginObject();
- * j.UnsafeWritePair("\"adam\": \"male\", \"eve\": \"female\"");
- * j.EndObject();
- *
- * As in all of the Unsafe* functions, no escaping is done. */
+ * that represents a key:value pair (or several pairs).
+ *
+ * Example:
+ * j.BeginObject();
+ * j.UnsafeWritePair("\"adam\": \"male\", \"eve\": \"female\"");
+ * j.EndObject();
+ *
+ * As in all of the Unsafe* functions, no escaping is done. */
TPairContext UnsafeWritePair(const TStringBuf& s);
/*** Copy the supplied string directly into the output stream. */
@@ -286,4 +286,4 @@ namespace NJsonWriter {
}
TString WrapJsonToCallback(const TBuf& buf, TStringBuf callback);
-}
+} // namespace NJsonWriter
diff --git a/library/cpp/json/writer/json_ut.cpp b/library/cpp/json/writer/json_ut.cpp
index 1768e912249..564b9ac8adf 100644
--- a/library/cpp/json/writer/json_ut.cpp
+++ b/library/cpp/json/writer/json_ut.cpp
@@ -265,4 +265,4 @@ Y_UNIT_TEST_SUITE(JsonWriter) {
UNIT_ASSERT_STRINGS_EQUAL(buf.Str(), R"({"\u003C\u003E&":"Ololo","<>&":"Ololo2"})");
}
}
-}
+} // Y_UNIT_TEST_SUITE(JsonWriter)
diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp
index e71e9ce8199..6a0546fe043 100644
--- a/library/cpp/json/writer/json_value.cpp
+++ b/library/cpp/json/writer/json_value.cpp
@@ -20,25 +20,25 @@ AreJsonMapsEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) {
Y_ABORT_UNLESS(lhs.GetType() == JSON_MAP, "lhs has not a JSON_MAP type.");
- if (rhs.GetType() != JSON_MAP)
+ if (rhs.GetType() != JSON_MAP) {
return false;
-
+ }
typedef TJsonValue::TMapType TMapType;
const TMapType& lhsMap = lhs.GetMap();
const TMapType& rhsMap = rhs.GetMap();
- if (lhsMap.size() != rhsMap.size())
+ if (lhsMap.size() != rhsMap.size()) {
return false;
-
+ }
for (const auto& lhsIt : lhsMap) {
TMapType::const_iterator rhsIt = rhsMap.find(lhsIt.first);
- if (rhsIt == rhsMap.end())
+ if (rhsIt == rhsMap.end()) {
return false;
-
- if (lhsIt.second != rhsIt->second)
+ }
+ if (lhsIt.second != rhsIt->second) {
return false;
+ }
}
-
return true;
}
@@ -48,22 +48,22 @@ AreJsonArraysEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) {
Y_ABORT_UNLESS(lhs.GetType() == JSON_ARRAY, "lhs has not a JSON_ARRAY type.");
- if (rhs.GetType() != JSON_ARRAY)
+ if (rhs.GetType() != JSON_ARRAY) {
return false;
-
+ }
typedef TJsonValue::TArray TArray;
const TArray& lhsArray = lhs.GetArray();
const TArray& rhsArray = rhs.GetArray();
- if (lhsArray.size() != rhsArray.size())
+ if (lhsArray.size() != rhsArray.size()) {
return false;
-
+ }
for (TArray::const_iterator lhsIt = lhsArray.begin(), rhsIt = rhsArray.begin();
lhsIt != lhsArray.end(); ++lhsIt, ++rhsIt) {
- if (*lhsIt != *rhsIt)
+ if (*lhsIt != *rhsIt) {
return false;
+ }
}
-
return true;
}
@@ -106,16 +106,18 @@ namespace NJson {
}
TJsonValue& TJsonValue::operator=(const TJsonValue& val) {
- if (this == &val)
+ if (this == &val) {
return *this;
+ }
TJsonValue tmp(val);
tmp.Swap(*this);
return *this;
}
TJsonValue& TJsonValue::operator=(TJsonValue&& val) noexcept {
- if (this == &val)
+ if (this == &val) {
return *this;
+ }
TJsonValue tmp(std::move(val));
tmp.Swap(*this);
return *this;
@@ -181,12 +183,11 @@ namespace NJson {
}
TJsonValue& TJsonValue::SetType(const EJsonValueType type) {
- if (Type == type)
+ if (Type == type) {
return *this;
-
+ }
Clear();
Type = type;
-
switch (Type) {
case JSON_STRING:
new (&Value.String) TString();
@@ -205,7 +206,6 @@ namespace NJson {
case JSON_DOUBLE:
break;
}
-
return *this;
}
@@ -273,8 +273,9 @@ namespace NJson {
void TJsonValue::EraseValue(const TStringBuf key) {
if (IsMap()) {
TMapType::iterator it = Value.Map->find(key);
- if (it != Value.Map->end())
+ if (it != Value.Map->end()) {
Value.Map->erase(it);
+ }
}
}
@@ -313,8 +314,9 @@ namespace NJson {
TJsonValue& TJsonValue::operator[](const size_t idx) {
SetType(JSON_ARRAY);
- if (Value.Array->size() <= idx)
+ if (Value.Array->size() <= idx) {
Value.Array->resize(idx + 1);
+ }
return (*Value.Array)[idx];
}
@@ -330,21 +332,21 @@ namespace NJson {
const TJsonValue::TArray Array{};
const TJsonValue Value{};
};
- }
+ } // namespace
const TJsonValue& TJsonValue::operator[](const size_t idx) const noexcept {
const TJsonValue* ret = nullptr;
- if (GetValuePointer(idx, &ret))
+ if (GetValuePointer(idx, &ret)) {
return *ret;
-
+ }
return Singleton<TDefaultsHolder>()->Value;
}
const TJsonValue& TJsonValue::operator[](const TStringBuf& key) const noexcept {
const TJsonValue* ret = nullptr;
- if (GetValuePointer(key, &ret))
+ if (GetValuePointer(key, &ret)) {
return *ret;
-
+ }
return Singleton<TDefaultsHolder>()->Value;
}
@@ -353,9 +355,9 @@ namespace NJson {
}
long long TJsonValue::GetInteger() const {
- if (!IsInteger())
+ if (!IsInteger()) {
return 0;
-
+ }
switch (Type) {
case JSON_INTEGER:
return Value.Integer;
@@ -373,19 +375,16 @@ namespace NJson {
}
unsigned long long TJsonValue::GetUInteger() const {
- if (!IsUInteger())
+ if (!IsUInteger()) {
return 0;
-
+ }
switch (Type) {
case JSON_UINTEGER:
return Value.UInteger;
-
case JSON_INTEGER:
return Value.Integer;
-
case JSON_DOUBLE:
return Value.Double;
-
default:
Y_ASSERT(false && "Unexpected type.");
return 0;
@@ -393,19 +392,16 @@ namespace NJson {
}
double TJsonValue::GetDouble() const {
- if (!IsDouble())
+ if (!IsDouble()) {
return 0.0;
-
+ }
switch (Type) {
case JSON_DOUBLE:
return Value.Double;
-
case JSON_INTEGER:
return Value.Integer;
-
case JSON_UINTEGER:
return Value.UInteger;
-
default:
Y_ASSERT(false && "Unexpected type.");
return 0.0;
@@ -425,79 +421,79 @@ namespace NJson {
}
bool TJsonValue::GetBooleanSafe() const {
- if (Type != JSON_BOOLEAN)
+ if (Type != JSON_BOOLEAN) {
ythrow TJsonException() << "Not a boolean";
-
+ }
return Value.Boolean;
}
long long TJsonValue::GetIntegerSafe() const {
- if (!IsInteger())
+ if (!IsInteger()) {
ythrow TJsonException() << "Not an integer";
-
+ }
return GetInteger();
}
unsigned long long TJsonValue::GetUIntegerSafe() const {
- if (!IsUInteger())
+ if (!IsUInteger()) {
ythrow TJsonException() << "Not an unsigned integer";
-
+ }
return GetUInteger();
}
double TJsonValue::GetDoubleSafe() const {
- if (!IsDouble())
+ if (!IsDouble()) {
ythrow TJsonException() << "Not a double";
-
+ }
return GetDouble();
}
const TString& TJsonValue::GetStringSafe() const {
- if (Type != JSON_STRING)
+ if (Type != JSON_STRING) {
ythrow TJsonException() << "Not a string";
-
+ }
return Value.String;
}
bool TJsonValue::GetBooleanSafe(const bool defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetBooleanSafe();
}
long long TJsonValue::GetIntegerSafe(const long long defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetIntegerSafe();
}
unsigned long long TJsonValue::GetUIntegerSafe(const unsigned long long defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetUIntegerSafe();
}
double TJsonValue::GetDoubleSafe(const double defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetDoubleSafe();
}
TString TJsonValue::GetStringSafe(const TString& defaultValue) const {
- if (Type == JSON_UNDEFINED)
+ if (Type == JSON_UNDEFINED) {
return defaultValue;
-
+ }
return GetStringSafe();
}
const TJsonValue::TMapType& TJsonValue::GetMapSafe() const {
- if (Type != JSON_MAP)
+ if (Type != JSON_MAP) {
ythrow TJsonException() << "Not a map";
-
+ }
return *Value.Map;
}
@@ -506,9 +502,9 @@ namespace NJson {
}
const TJsonValue::TArray& TJsonValue::GetArraySafe() const {
- if (Type != JSON_ARRAY)
+ if (Type != JSON_ARRAY) {
ythrow TJsonException() << "Not an array";
-
+ }
return *Value.Array;
}
@@ -646,73 +642,73 @@ namespace NJson {
}
bool TJsonValue::GetBoolean(bool* value) const noexcept {
- if (Type != JSON_BOOLEAN)
+ if (Type != JSON_BOOLEAN) {
return false;
-
+ }
*value = Value.Boolean;
return true;
}
bool TJsonValue::GetInteger(long long* value) const noexcept {
- if (!IsInteger())
+ if (!IsInteger()) {
return false;
-
+ }
*value = GetInteger();
return true;
}
bool TJsonValue::GetUInteger(unsigned long long* value) const noexcept {
- if (!IsUInteger())
+ if (!IsUInteger()) {
return false;
-
+ }
*value = GetUInteger();
return true;
}
bool TJsonValue::GetDouble(double* value) const noexcept {
- if (!IsDouble())
+ if (!IsDouble()) {
return false;
-
+ }
*value = GetDouble();
return true;
}
bool TJsonValue::GetString(TString* value) const {
- if (Type != JSON_STRING)
+ if (Type != JSON_STRING) {
return false;
-
+ }
*value = Value.String;
return true;
}
bool TJsonValue::GetMap(TJsonValue::TMapType* value) const {
- if (Type != JSON_MAP)
+ if (Type != JSON_MAP) {
return false;
-
+ }
*value = *Value.Map;
return true;
}
bool TJsonValue::GetArray(TJsonValue::TArray* value) const {
- if (Type != JSON_ARRAY)
+ if (Type != JSON_ARRAY) {
return false;
-
+ }
*value = *Value.Array;
return true;
}
bool TJsonValue::GetMapPointer(const TJsonValue::TMapType** value) const noexcept {
- if (Type != JSON_MAP)
+ if (Type != JSON_MAP) {
return false;
-
+ }
*value = Value.Map;
return true;
}
bool TJsonValue::GetArrayPointer(const TJsonValue::TArray** value) const noexcept {
- if (Type != JSON_ARRAY)
+ if (Type != JSON_ARRAY) {
return false;
-
+ }
*value = Value.Array;
return true;
}
@@ -770,13 +766,10 @@ namespace NJson {
switch (Type) {
case JSON_INTEGER:
return true;
-
case JSON_UINTEGER:
return (Value.UInteger <= static_cast<unsigned long long>(Max<long long>()));
-
case JSON_DOUBLE:
return ((long long)Value.Double == Value.Double);
-
default:
return false;
}
@@ -786,13 +779,10 @@ namespace NJson {
switch (Type) {
case JSON_UINTEGER:
return true;
-
case JSON_INTEGER:
return (Value.Integer >= 0);
-
case JSON_DOUBLE:
return ((unsigned long long)Value.Double == Value.Double);
-
default:
return false;
}
@@ -804,13 +794,10 @@ namespace NJson {
switch (Type) {
case JSON_DOUBLE:
return true;
-
case JSON_INTEGER:
return (1ll << std::numeric_limits<double>::digits) >= Abs(Value.Integer);
-
case JSON_UINTEGER:
return (1ull << std::numeric_limits<double>::digits) >= Value.UInteger;
-
default:
return false;
}
@@ -860,12 +847,10 @@ namespace NJson {
} else {
currentJson = CreateOrNullptr(currentJson, step, create_tag);
}
-
if (!currentJson) {
return nullptr;
}
}
-
return currentJson;
}
} // anonymous namespace
@@ -909,7 +894,6 @@ namespace NJson {
if (!callback.Do(path, parent, *this)) {
return;
}
-
if (Type == JSON_MAP) {
for (auto&& i : *Value.Map) {
i.second.DoScan(!!path ? TString::Join(path, ".", i.first) : i.first, this, callback);
@@ -947,40 +931,24 @@ namespace NJson {
bool TJsonValue::operator==(const TJsonValue& rhs) const {
switch (Type) {
- case JSON_UNDEFINED: {
+ case JSON_UNDEFINED:
return (rhs.GetType() == JSON_UNDEFINED);
- }
-
- case JSON_NULL: {
+ case JSON_NULL:
return rhs.IsNull();
- }
-
- case JSON_BOOLEAN: {
+ case JSON_BOOLEAN:
return (rhs.IsBoolean() && Value.Boolean == rhs.Value.Boolean);
- }
-
- case JSON_INTEGER: {
+ case JSON_INTEGER:
return (rhs.IsInteger() && GetInteger() == rhs.GetInteger());
- }
-
- case JSON_UINTEGER: {
+ case JSON_UINTEGER:
return (rhs.IsUInteger() && GetUInteger() == rhs.GetUInteger());
- }
-
- case JSON_STRING: {
+ case JSON_STRING:
return (rhs.IsString() && Value.String == rhs.Value.String);
- }
-
- case JSON_DOUBLE: {
+ case JSON_DOUBLE:
return (rhs.IsDouble() && fabs(GetDouble() - rhs.GetDouble()) <= FLT_EPSILON);
- }
-
case JSON_MAP:
return AreJsonMapsEqual(*this, rhs);
-
case JSON_ARRAY:
return AreJsonArraysEqual(*this, rhs);
-
default:
Y_ASSERT(false && "Unknown type.");
return false;
@@ -995,7 +963,6 @@ namespace NJson {
} else {
std::memcpy(&output.Value, &Value, sizeof(Value));
}
-
output.Type = Type;
Type = JSON_UNDEFINED;
}
@@ -1009,8 +976,10 @@ namespace NJson {
void TJsonValue::Save(IOutputStream* s) const {
::Save(s, static_cast<ui8>(Type));
switch (Type) {
- case JSON_UNDEFINED:break;
- case JSON_NULL:break;
+ case JSON_UNDEFINED:
+ break;
+ case JSON_NULL:
+ break;
case JSON_BOOLEAN:
::Save(s, Value.Boolean);
break;
@@ -1042,8 +1011,10 @@ namespace NJson {
SetType(static_cast<EJsonValueType>(loadedType));
}
switch (Type) {
- case JSON_UNDEFINED:break;
- case JSON_NULL:break;
+ case JSON_UNDEFINED:
+ break;
+ case JSON_NULL:
+ break;
case JSON_BOOLEAN:
::Load(s, Value.Boolean);
break;
@@ -1072,48 +1043,49 @@ namespace NJson {
bool GetMapPointer(const TJsonValue& jv, const size_t index, const TJsonValue::TMapType** value) {
const TJsonValue* v;
- if (!jv.GetValuePointer(index, &v) || !v->IsMap())
+ if (!jv.GetValuePointer(index, &v) || !v->IsMap()) {
return false;
-
+ }
*value = &v->GetMap();
return true;
}
bool GetArrayPointer(const TJsonValue& jv, const size_t index, const TJsonValue::TArray** value) {
const TJsonValue* v;
- if (!jv.GetValuePointer(index, &v) || !v->IsArray())
+ if (!jv.GetValuePointer(index, &v) || !v->IsArray()) {
return false;
-
+ }
*value = &v->GetArray();
return true;
}
bool GetMapPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TMapType** value) {
const TJsonValue* v;
- if (!jv.GetValuePointer(key, &v) || !v->IsMap())
+ if (!jv.GetValuePointer(key, &v) || !v->IsMap()) {
return false;
-
+ }
*value = &v->GetMap();
return true;
}
bool GetArrayPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TArray** value) {
const TJsonValue* v;
- if (!jv.GetValuePointer(key, &v) || !v->IsArray())
+ if (!jv.GetValuePointer(key, &v) || !v->IsArray()) {
return false;
-
+ }
*value = &v->GetArray();
return true;
}
void TJsonValue::BackChecks() const {
- if (Type != JSON_ARRAY)
+ if (Type != JSON_ARRAY) {
ythrow TJsonException() << "Not an array";
-
- if (Value.Array->empty())
+ }
+ if (Value.Array->empty()) {
ythrow TJsonException() << "Get back on empty array";
+ }
}
-}
+} // namespace NJson
template <>
void Out<NJson::TJsonValue>(IOutputStream& out, const NJson::TJsonValue& v) {
diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h
index 789a629807c..ec919697dc7 100644
--- a/library/cpp/json/writer/json_value.h
+++ b/library/cpp/json/writer/json_value.h
@@ -120,7 +120,7 @@ namespace NJson {
const TMapType& GetMap() const Y_LIFETIME_BOUND;
const TArray& GetArray() const Y_LIFETIME_BOUND;
- //throwing TJsonException possible
+ // throwing TJsonException possible
bool GetBooleanSafe() const;
long long GetIntegerSafe() const;
unsigned long long GetUIntegerSafe() const;
@@ -273,7 +273,8 @@ namespace NJson {
public:
TJsonMap()
: TJsonValue(NJson::JSON_MAP)
- {}
+ {
+ }
TJsonMap(const std::initializer_list<std::pair<TString, TJsonValue>>& list)
: TJsonValue(NJson::JSON_MAP)
@@ -286,7 +287,8 @@ namespace NJson {
public:
TJsonArray()
: TJsonValue(NJson::JSON_ARRAY)
- {}
+ {
+ }
TJsonArray(const std::initializer_list<TJsonValue>& list)
: TJsonValue(NJson::JSON_ARRAY)
@@ -294,4 +296,4 @@ namespace NJson {
GetArraySafe() = TJsonValue::TArray(list);
}
};
-}
+} // namespace NJson
diff --git a/library/cpp/json/writer/json_value_ut.cpp b/library/cpp/json/writer/json_value_ut.cpp
index 6fc1e56f792..21b396a64de 100644
--- a/library/cpp/json/writer/json_value_ut.cpp
+++ b/library/cpp/json/writer/json_value_ut.cpp
@@ -8,10 +8,10 @@ using namespace NJson;
Y_UNIT_TEST_SUITE(TJsonValueTest) {
Y_UNIT_TEST(Equal) {
- UNIT_ASSERT(1 == TJsonValue(1));
- UNIT_ASSERT(TJsonValue(1) == 1);
- UNIT_ASSERT(2 != TJsonValue(1));
- UNIT_ASSERT(TJsonValue(1) != 2);
+ UNIT_ASSERT(1 == TJsonValue(1));
+ UNIT_ASSERT(TJsonValue(1) == 1);
+ UNIT_ASSERT(2 != TJsonValue(1));
+ UNIT_ASSERT(TJsonValue(1) != 2);
}
Y_UNIT_TEST(UndefTest) {
@@ -175,15 +175,16 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
const int NUM_KEYS = 1000;
TJsonValue lhs;
- for (int i = 0; i < NUM_KEYS; ++i)
+ for (int i = 0; i < NUM_KEYS; ++i) {
lhs.InsertValue(ToString(i), i);
-
+ }
TJsonValue rhs;
- for (int i = 0; i < NUM_KEYS; i += 2)
+ for (int i = 0; i < NUM_KEYS; i += 2) {
rhs.InsertValue(ToString(i), i);
- for (int i = 1; i < NUM_KEYS; i += 2)
+ }
+ for (int i = 1; i < NUM_KEYS; i += 2) {
rhs.InsertValue(ToString(i), i);
-
+ }
UNIT_ASSERT(lhs == rhs);
UNIT_ASSERT(rhs == lhs);
}
@@ -681,4 +682,4 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
UNIT_ASSERT_VALUES_EQUAL(filled["4"].GetMapSafe().size(), 1);
UNIT_ASSERT_VALUES_EQUAL(filled["4"]["5"], TJsonValue{5});
}
-} // TJsonValueTest
+} // Y_UNIT_TEST_SUITE(TJsonValueTest)
diff --git a/library/cpp/json/yson/json2yson.cpp b/library/cpp/json/yson/json2yson.cpp
index f72cb7a9ef9..400e46466b7 100644
--- a/library/cpp/json/yson/json2yson.cpp
+++ b/library/cpp/json/yson/json2yson.cpp
@@ -29,8 +29,9 @@ namespace NJson2Yson {
case NJson::JSON_ARRAY: {
adapter->OnOpenArray();
const NJson::TJsonValue::TArray& arr = jsonValue.GetArray();
- for (const auto& it : arr)
+ for (const auto& it : arr) {
WriteJsonValue(it, adapter);
+ }
adapter->OnCloseArray();
break;
}
@@ -105,4 +106,4 @@ namespace NJson2Yson {
ConvertYson2Json(yson, &outputStream);
return json;
}
-}
+} // namespace NJson2Yson
diff --git a/library/cpp/json/yson/json2yson.h b/library/cpp/json/yson/json2yson.h
index 6e3bcf5b8ef..7da1e223bc8 100644
--- a/library/cpp/json/yson/json2yson.h
+++ b/library/cpp/json/yson/json2yson.h
@@ -176,4 +176,4 @@ namespace NJson2Yson {
void SerializeJsonValueAsYson(const NJson::TJsonValue& inputValue, IOutputStream* outputStream);
void SerializeJsonValueAsYson(const NJson::TJsonValue& inputValue, TString& result);
TString SerializeJsonValueAsYson(const NJson::TJsonValue& inputValue);
-}
+} // namespace NJson2Yson
diff --git a/library/cpp/json/yson/json2yson_ut.cpp b/library/cpp/json/yson/json2yson_ut.cpp
index 9eb23354cf0..cf5ea41d2ff 100644
--- a/library/cpp/json/yson/json2yson_ut.cpp
+++ b/library/cpp/json/yson/json2yson_ut.cpp
@@ -104,4 +104,4 @@ Y_UNIT_TEST_SUITE(Json2Yson) {
}
}
}
-}
+} // Y_UNIT_TEST_SUITE(Json2Yson)