summaryrefslogtreecommitdiffstats
path: root/library/cpp/json/ordered_maps
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 /library/cpp/json/ordered_maps
parentf4cbf746a0b6649479cfb305eceababced0ac10a (diff)
Style fix
commit_hash:d506e2a0f2770f3662449a3711e976499eb9ccbb
Diffstat (limited to 'library/cpp/json/ordered_maps')
-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
14 files changed, 199 insertions, 234 deletions
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)