aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authormyltsev <myltsev@yandex-team.ru>2022-02-10 16:46:03 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:03 +0300
commit9166d66c30c23c9e85a7c88185a068987148d23f (patch)
tree421bdcec5755d9e441c485560aab5ab8d74c7475 /library
parent8d3a5ed3a188a34167eaee54f1691ce5c9edf2f3 (diff)
downloadydb-9166d66c30c23c9e85a7c88185a068987148d23f.tar.gz
Restoring authorship annotation for <myltsev@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library')
-rw-r--r--library/cpp/containers/comptrie/comptrie_builder.h2
-rw-r--r--library/cpp/getopt/small/last_getopt_opt.h14
-rw-r--r--library/cpp/getopt/ut/last_getopt_ut.cpp12
-rw-r--r--library/cpp/http/io/headers.cpp12
-rw-r--r--library/cpp/http/io/headers.h4
-rw-r--r--library/cpp/http/io/stream.cpp8
-rw-r--r--library/cpp/http/io/stream_ut.cpp36
-rw-r--r--library/cpp/http/misc/httpdate.cpp6
-rw-r--r--library/cpp/http/misc/httpdate.h2
-rw-r--r--library/cpp/http/misc/httpdate_ut.cpp4
-rw-r--r--library/cpp/http/server/response.h8
-rw-r--r--library/cpp/json/easy_parse/json_easy_parser_impl.h14
-rw-r--r--library/cpp/json/json_value.h4
-rw-r--r--library/cpp/json/json_writer.cpp6
-rw-r--r--library/cpp/json/json_writer.h2
-rw-r--r--library/cpp/json/ut/json_writer_ut.cpp22
-rw-r--r--library/cpp/json/writer/README44
-rw-r--r--library/cpp/json/writer/json.cpp136
-rw-r--r--library/cpp/json/writer/json.h330
-rw-r--r--library/cpp/json/writer/json_ut.cpp280
-rw-r--r--library/cpp/json/writer/json_value.cpp8
-rw-r--r--library/cpp/json/writer/json_value.h2
-rw-r--r--library/cpp/json/writer/ya.make16
-rw-r--r--library/cpp/packers/region_packer.h14
-rw-r--r--library/cpp/packers/ut/region_packer_ut.cpp60
-rw-r--r--library/cpp/protobuf/json/json2proto.h4
-rw-r--r--library/cpp/sighandler/async_signals_handler.cpp18
-rw-r--r--library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h20
-rw-r--r--library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp8
-rw-r--r--library/cpp/string_utils/levenshtein_diff/ut/ya.make8
-rw-r--r--library/cpp/string_utils/ya.make6
-rw-r--r--library/cpp/string_utils/ztstrbuf/ya.make18
-rw-r--r--library/cpp/string_utils/ztstrbuf/ztstrbuf.cpp16
-rw-r--r--library/cpp/string_utils/ztstrbuf/ztstrbuf.h70
-rw-r--r--library/cpp/xml/document/README36
-rw-r--r--library/cpp/xml/document/libxml-guards.h18
-rw-r--r--library/cpp/xml/document/node-attr.h80
-rw-r--r--library/cpp/xml/document/xml-document-decl.h302
-rw-r--r--library/cpp/xml/document/xml-document.cpp118
-rw-r--r--library/cpp/xml/document/xml-document.h4
-rw-r--r--library/cpp/xml/document/xml-document_ut.cpp112
-rw-r--r--library/cpp/xml/document/xml-textreader.cpp10
-rw-r--r--library/cpp/xml/document/xml-textreader.h14
-rw-r--r--library/cpp/xml/document/ya.make2
-rw-r--r--library/cpp/xml/init/ptr.h2
-rw-r--r--library/python/ya.make2
46 files changed, 957 insertions, 957 deletions
diff --git a/library/cpp/containers/comptrie/comptrie_builder.h b/library/cpp/containers/comptrie/comptrie_builder.h
index cf7d2e39a3..39a394f6ef 100644
--- a/library/cpp/containers/comptrie/comptrie_builder.h
+++ b/library/cpp/containers/comptrie/comptrie_builder.h
@@ -115,7 +115,7 @@ protected:
// IMPORTANT: never try to reminimize an already minimized trie or a trie with fast layout.
// Because of non-local structure and epsilon links, it won't work
// as you expect it to, and can destroy the trie in the making.
-// If you want both minimization and fast layout, do the minimization first.
+// If you want both minimization and fast layout, do the minimization first.
template <class TPacker>
size_t CompactTrieMinimize(IOutputStream& os, const char* data, size_t datalength, bool verbose = false, const TPacker& packer = TPacker(), NCompactTrie::EMinimizeMode mode = NCompactTrie::MM_DEFAULT);
diff --git a/library/cpp/getopt/small/last_getopt_opt.h b/library/cpp/getopt/small/last_getopt_opt.h
index a8dd5adca9..f1ed8c7017 100644
--- a/library/cpp/getopt/small/last_getopt_opt.h
+++ b/library/cpp/getopt/small/last_getopt_opt.h
@@ -637,11 +637,11 @@ namespace NLastGetopt {
return DefaultValue("0").StoreResult(target, true);
}
- // Similar to store_true in Python's argparse
- TOpt& StoreTrue(bool* target) {
- return NoArgument().SetFlag(target);
- }
-
+ // Similar to store_true in Python's argparse
+ TOpt& StoreTrue(bool* target) {
+ return NoArgument().SetFlag(target);
+ }
+
template <typename TpVal, typename T, typename TpFunc>
TOpt& StoreMappedResultT(T* target, const TpFunc& func) {
return Handler1T<TpVal>(NPrivate::TStoreMappedResultFunctor<T, TpFunc, TpVal>(target, func));
@@ -675,13 +675,13 @@ namespace NLastGetopt {
// Appends FromString<T>(arg) to *target for each argument
template <typename T>
TOpt& AppendTo(TVector<T>* target) {
- return Handler1T<T>([target](auto&& value) { target->push_back(std::move(value)); });
+ return Handler1T<T>([target](auto&& value) { target->push_back(std::move(value)); });
}
// Appends FromString<T>(arg) to *target for each argument
template <typename T>
TOpt& InsertTo(THashSet<T>* target) {
- return Handler1T<T>([target](auto&& value) { target->insert(std::move(value)); });
+ return Handler1T<T>([target](auto&& value) { target->insert(std::move(value)); });
}
// Emplaces TString arg to *target for each argument
diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp
index c99a1d053d..cec948ecac 100644
--- a/library/cpp/getopt/ut/last_getopt_ut.cpp
+++ b/library/cpp/getopt/ut/last_getopt_ut.cpp
@@ -455,20 +455,20 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) {
}
Y_UNIT_TEST(TestSetFlag) {
- bool a = false, b = true, c = false, d = true;
+ bool a = false, b = true, c = false, d = true;
TOptsNoDefault opts;
opts.AddLongOption('a', "alpha").NoArgument().SetFlag(&a);
opts.AddLongOption('b', "beta").NoArgument().SetFlag(&b);
- opts.AddCharOption('c').StoreTrue(&c);
- opts.AddCharOption('d').StoreTrue(&d);
+ opts.AddCharOption('c').StoreTrue(&c);
+ opts.AddCharOption('d').StoreTrue(&d);
- TOptsParseResultTestWrapper r(&opts, V({"cmd", "-a", "-c"}));
+ TOptsParseResultTestWrapper r(&opts, V({"cmd", "-a", "-c"}));
UNIT_ASSERT(a);
UNIT_ASSERT(!b);
- UNIT_ASSERT(c);
- UNIT_ASSERT(!d);
+ UNIT_ASSERT(c);
+ UNIT_ASSERT(!d);
}
Y_UNIT_TEST(TestDefaultValue) {
diff --git a/library/cpp/http/io/headers.cpp b/library/cpp/http/io/headers.cpp
index 4ec27a29e8..fe82383318 100644
--- a/library/cpp/http/io/headers.cpp
+++ b/library/cpp/http/io/headers.cpp
@@ -75,12 +75,12 @@ const THttpInputHeader* THttpHeaders::FindHeader(const TStringBuf header) const
void THttpHeaders::RemoveHeader(const TStringBuf header) {
for (auto h = Headers_.begin(); h != Headers_.end(); ++h) {
if (AsciiCompareIgnoreCase(h->Name(), header) == 0) {
- Headers_.erase(h);
- return;
- }
- }
-}
-
+ Headers_.erase(h);
+ return;
+ }
+ }
+}
+
void THttpHeaders::AddOrReplaceHeader(const THttpInputHeader& header) {
for (auto& hdr : Headers_) {
if (AsciiCompareIgnoreCase(hdr.Name(), header.Name()) == 0) {
diff --git a/library/cpp/http/io/headers.h b/library/cpp/http/io/headers.h
index a71793d1c6..3b15d60462 100644
--- a/library/cpp/http/io/headers.h
+++ b/library/cpp/http/io/headers.h
@@ -102,9 +102,9 @@ public:
// Проверяет, есть ли такой заголовок
bool HasHeader(TStringBuf header) const;
- /// Удаляет заголовок, если он есть.
+ /// Удаляет заголовок, если он есть.
void RemoveHeader(TStringBuf header);
-
+
/// Ищет заголовок по указанному имени
/// Возвращает nullptr, если не нашел
const THttpInputHeader* FindHeader(TStringBuf header) const;
diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp
index 6689be684f..90d063a4ba 100644
--- a/library/cpp/http/io/stream.cpp
+++ b/library/cpp/http/io/stream.cpp
@@ -776,7 +776,7 @@ private:
TString scheme = Request_->BestCompressionScheme(ComprSchemas_);
if (scheme != "identity") {
AddOrReplaceHeader(THttpInputHeader("Content-Encoding", scheme));
- RemoveHeader("Content-Length");
+ RemoveHeader("Content-Length");
}
}
@@ -851,9 +851,9 @@ private:
}
inline void RemoveHeader(const TString& hdr) {
- Headers_.RemoveHeader(hdr);
- }
-
+ Headers_.RemoveHeader(hdr);
+ }
+
private:
IOutputStream* Slave_;
TState State_;
diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp
index 1ea35df675..64b48b4a66 100644
--- a/library/cpp/http/io/stream_ut.cpp
+++ b/library/cpp/http/io/stream_ut.cpp
@@ -420,27 +420,27 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) {
}
Y_UNIT_TEST(ContentLengthRemoval) {
- TMemoryInput request("GET / HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n");
- THttpInput i(&request);
+ TMemoryInput request("GET / HTTP/1.1\r\nAccept-Encoding: gzip\r\n\r\n");
+ THttpInput i(&request);
TString result;
- TStringOutput out(result);
- THttpOutput httpOut(&out, &i);
-
- httpOut.EnableKeepAlive(true);
- httpOut.EnableCompression(true);
- httpOut << "HTTP/1.1 200 OK\r\n";
- char answer[] = "Mary had a little lamb.";
+ TStringOutput out(result);
+ THttpOutput httpOut(&out, &i);
+
+ httpOut.EnableKeepAlive(true);
+ httpOut.EnableCompression(true);
+ httpOut << "HTTP/1.1 200 OK\r\n";
+ char answer[] = "Mary had a little lamb.";
httpOut << "Content-Length: " << strlen(answer) << "\r\n"
"\r\n";
- httpOut << answer;
- httpOut.Finish();
-
- Cdbg << result;
- result.to_lower();
- UNIT_ASSERT(result.Contains("content-encoding: gzip"));
- UNIT_ASSERT(!result.Contains("content-length"));
- }
-
+ httpOut << answer;
+ httpOut.Finish();
+
+ Cdbg << result;
+ result.to_lower();
+ UNIT_ASSERT(result.Contains("content-encoding: gzip"));
+ UNIT_ASSERT(!result.Contains("content-length"));
+ }
+
Y_UNIT_TEST(CodecsPriority) {
TMemoryInput request("GET / HTTP/1.1\r\nAccept-Encoding: gzip, br\r\n\r\n");
TVector<TStringBuf> codecs = {"br", "gzip"};
diff --git a/library/cpp/http/misc/httpdate.cpp b/library/cpp/http/misc/httpdate.cpp
index 4a3031bbf4..1d6617eeec 100644
--- a/library/cpp/http/misc/httpdate.cpp
+++ b/library/cpp/http/misc/httpdate.cpp
@@ -75,9 +75,9 @@ char* format_http_date(time_t when, char* buf, size_t buflen) {
return buf;
}
-
+
TString FormatHttpDate(time_t when) {
- char str[64] = {0};
+ char str[64] = {0};
format_http_date(str, Y_ARRAY_SIZE(str), when);
return TString(str);
-}
+}
diff --git a/library/cpp/http/misc/httpdate.h b/library/cpp/http/misc/httpdate.h
index 04876f38fe..2a33545a7e 100644
--- a/library/cpp/http/misc/httpdate.h
+++ b/library/cpp/http/misc/httpdate.h
@@ -17,5 +17,5 @@ inline time_t parse_http_date(const TStringBuf& datestring) {
int format_http_date(char buf[], size_t size, time_t when);
char* format_http_date(time_t when, char* buf, size_t len);
-
+
TString FormatHttpDate(time_t when);
diff --git a/library/cpp/http/misc/httpdate_ut.cpp b/library/cpp/http/misc/httpdate_ut.cpp
index c1a0103501..8d700a9593 100644
--- a/library/cpp/http/misc/httpdate_ut.cpp
+++ b/library/cpp/http/misc/httpdate_ut.cpp
@@ -10,6 +10,6 @@ Y_UNIT_TEST_SUITE(TestHttpDate) {
UNIT_ASSERT((int)strlen(format_http_date(0, buf1, sizeof(buf1))) == format_http_date(buf2, sizeof(buf2), 0));
}
Y_UNIT_TEST(Test2) {
- UNIT_ASSERT_STRINGS_EQUAL(FormatHttpDate(1234567890), "Fri, 13 Feb 2009 23:31:30 GMT");
- }
+ UNIT_ASSERT_STRINGS_EQUAL(FormatHttpDate(1234567890), "Fri, 13 Feb 2009 23:31:30 GMT");
+ }
}
diff --git a/library/cpp/http/server/response.h b/library/cpp/http/server/response.h
index a75cb85605..05a4d53caa 100644
--- a/library/cpp/http/server/response.h
+++ b/library/cpp/http/server/response.h
@@ -51,10 +51,10 @@ public:
return *this;
}
- TString GetContent() const {
- return Content;
- }
-
+ TString GetContent() const {
+ return Content;
+ }
+
/**
* @note If @arg content isn't empty its size is automatically added as a
* "Content-Length" header during output to IOutputStream.
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 ec55d838b3..9f9486c6f5 100644
--- a/library/cpp/json/easy_parse/json_easy_parser_impl.h
+++ b/library/cpp/json/easy_parse/json_easy_parser_impl.h
@@ -3,34 +3,34 @@
#include <util/generic/string.h>
namespace NJson {
- namespace NImpl {
+ namespace NImpl {
enum EType {
ARRAY,
MAP,
MAP_KEY
};
- }
+ }
template <class TStringType>
- struct TPathElemImpl {
- NImpl::EType Type;
+ struct TPathElemImpl {
+ NImpl::EType Type;
TStringType Key;
int ArrayCounter;
- TPathElemImpl(NImpl::EType type)
+ TPathElemImpl(NImpl::EType type)
: Type(type)
, ArrayCounter()
{
}
TPathElemImpl(const TStringType& key)
- : Type(NImpl::MAP_KEY)
+ : Type(NImpl::MAP_KEY)
, Key(key)
, ArrayCounter()
{
}
TPathElemImpl(int arrayCounter)
- : Type(NImpl::ARRAY)
+ : Type(NImpl::ARRAY)
, ArrayCounter(arrayCounter)
{
}
diff --git a/library/cpp/json/json_value.h b/library/cpp/json/json_value.h
index f70f4d2ee8..9109377521 100644
--- a/library/cpp/json/json_value.h
+++ b/library/cpp/json/json_value.h
@@ -1,3 +1,3 @@
-#pragma once
-
+#pragma once
+
#include <library/cpp/json/writer/json_value.h>
diff --git a/library/cpp/json/json_writer.cpp b/library/cpp/json/json_writer.cpp
index 3d058bae36..c9fc529135 100644
--- a/library/cpp/json/json_writer.cpp
+++ b/library/cpp/json/json_writer.cpp
@@ -73,14 +73,14 @@ namespace NJson {
throw yexception() << "JSON writer: invalid UTF-8";
if (Buf.KeyExpected()) {
Buf.WriteKey(value);
- } else {
+ } else {
if (DontEscapeStrings) {
Buf.UnsafeWriteValue(TString("\"") + value + '"');
} else {
Buf.WriteString(value);
}
- }
- }
+ }
+ }
void TJsonWriter::WriteNull() {
Buf.WriteNull();
diff --git a/library/cpp/json/json_writer.h b/library/cpp/json/json_writer.h
index c7f5c9499a..471ff3ed71 100644
--- a/library/cpp/json/json_writer.h
+++ b/library/cpp/json/json_writer.h
@@ -1,7 +1,7 @@
#pragma once
// Deprecated. Use library/cpp/json/writer in new code.
-
+
#include "json_value.h"
#include <library/cpp/json/writer/json.h>
diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp
index ca11d34dad..f4d9cde0e8 100644
--- a/library/cpp/json/ut/json_writer_ut.cpp
+++ b/library/cpp/json/ut/json_writer_ut.cpp
@@ -71,17 +71,17 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) {
Y_UNIT_TEST(SortKeys) {
TString expected = "{\"a\":null,\"j\":null,\"n\":null,\"y\":null,\"z\":null}";
- TJsonValue v;
- v["z"] = JSON_NULL;
- v["n"] = JSON_NULL;
- v["a"] = JSON_NULL;
- v["y"] = JSON_NULL;
- v["j"] = JSON_NULL;
- TStringStream out;
- WriteJson(&out, &v, false, true);
- UNIT_ASSERT_STRINGS_EQUAL(out.Str(), expected);
- }
-
+ TJsonValue v;
+ v["z"] = JSON_NULL;
+ v["n"] = JSON_NULL;
+ v["a"] = JSON_NULL;
+ v["y"] = JSON_NULL;
+ v["j"] = JSON_NULL;
+ TStringStream out;
+ WriteJson(&out, &v, false, true);
+ UNIT_ASSERT_STRINGS_EQUAL(out.Str(), expected);
+ }
+
Y_UNIT_TEST(SimpleUnsignedIntegerWriteTest) {
{
TString expected = "{\"test\":1}";
diff --git a/library/cpp/json/writer/README b/library/cpp/json/writer/README
index a20489f32e..6e6f754658 100644
--- a/library/cpp/json/writer/README
+++ b/library/cpp/json/writer/README
@@ -1,23 +1,23 @@
-JSON writer with no external dependencies, producing output
-where HTML special characters are always escaped.
-
-Use it like this:
-
+JSON writer with no external dependencies, producing output
+where HTML special characters are always escaped.
+
+Use it like this:
+
#include <library/cpp/json/writer/json.h>
- ...
-
- NJsonWriter::TBuf json;
- json.BeginList()
- .WriteString("<script>")
- .EndList();
- Cout << json.Str(); // output: ["\u003Cscript\u003E"]
-
-For compatibility with legacy formats where object keys
-are not quoted, use CompatWriteKeyWithoutQuotes:
-
- NJsonWriter::TBuf json;
- json.BeginObject()
- .CompatWriteKeyWithoutQuotes("r").WriteInt(1)
- .CompatWriteKeyWithoutQuotes("n").WriteInt(0)
- .EndObject();
- Cout << json.Str(); // output: {r:1,n:0}
+ ...
+
+ NJsonWriter::TBuf json;
+ json.BeginList()
+ .WriteString("<script>")
+ .EndList();
+ Cout << json.Str(); // output: ["\u003Cscript\u003E"]
+
+For compatibility with legacy formats where object keys
+are not quoted, use CompatWriteKeyWithoutQuotes:
+
+ NJsonWriter::TBuf json;
+ json.BeginObject()
+ .CompatWriteKeyWithoutQuotes("r").WriteInt(1)
+ .CompatWriteKeyWithoutQuotes("n").WriteInt(0)
+ .EndObject();
+ Cout << json.Str(); // output: {r:1,n:0}
diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp
index 02370c2d79..50523bf754 100644
--- a/library/cpp/json/writer/json.cpp
+++ b/library/cpp/json/writer/json.cpp
@@ -1,14 +1,14 @@
-#include "json.h"
+#include "json.h"
#include <library/cpp/json/json_value.h>
#include <util/string/cast.h>
#include <util/string/strspn.h>
-#include <util/generic/algorithm.h>
-#include <util/generic/ymath.h>
+#include <util/generic/algorithm.h>
+#include <util/generic/ymath.h>
#include <util/generic/singleton.h>
-
-namespace NJsonWriter {
+
+namespace NJsonWriter {
TBuf::TBuf(EHtmlEscapeMode mode, IOutputStream* stream)
: Stream(stream)
, NeedComma(false)
@@ -25,7 +25,7 @@ namespace NJsonWriter {
StringStream.Reset(new TStringStream);
Stream = StringStream.Get();
}
-
+
Stack.reserve(64); // should be enough for most cases
StackPush(JE_OUTER_SPACE);
}
@@ -47,12 +47,12 @@ namespace NJsonWriter {
inline void TBuf::StackPush(EJsonEntity e) {
Stack.push_back(e);
- }
-
+ }
+
inline EJsonEntity TBuf::StackTop() const {
return Stack.back();
}
-
+
inline void TBuf::StackPop() {
Y_ASSERT(!Stack.empty());
const EJsonEntity current = StackTop();
@@ -81,8 +81,8 @@ namespace NJsonWriter {
<< EntityToStr(StackTop()) << " on the stack";
}
StackPop();
- }
-
+ }
+
void TBuf::PrintIndentation(bool closing) {
if (!IndentSpaces)
return;
@@ -126,7 +126,7 @@ namespace NJsonWriter {
}
WriteComma();
}
-
+
inline void TBuf::BeginKey() {
if (Y_UNLIKELY(!KeyExpected())) {
ythrow TError() << "JSON writer: key written outside of an object";
@@ -135,14 +135,14 @@ namespace NJsonWriter {
StackPush(JE_PAIR);
NeedComma = false;
NeedNewline = false;
- }
+ }
inline void TBuf::EndValue() {
if (StackTop() == JE_PAIR) {
StackPop();
}
}
-
+
TValueContext TBuf::BeginList() {
NeedNewline = true;
BeginValue();
@@ -150,8 +150,8 @@ namespace NJsonWriter {
StackPush(JE_LIST);
NeedComma = false;
return TValueContext(*this);
- }
-
+ }
+
TPairContext TBuf::BeginObject() {
NeedNewline = true;
BeginValue();
@@ -159,28 +159,28 @@ namespace NJsonWriter {
StackPush(JE_OBJECT);
NeedComma = false;
return TPairContext(*this);
- }
-
+ }
+
TAfterColonContext TBuf::UnsafeWriteKey(const TStringBuf& s) {
BeginKey();
RawWriteChar('"');
UnsafeWriteRawBytes(s);
UnsafeWriteRawBytes("\":", 2);
return TAfterColonContext(*this);
- }
-
+ }
+
TAfterColonContext TBuf::WriteKey(const TStringBuf& s) {
// use the default escaping mode for this object
return WriteKey(s, EscapeMode);
}
-
+
TAfterColonContext TBuf::WriteKey(const TStringBuf& s, EHtmlEscapeMode hem) {
BeginKey();
WriteBareString(s, hem);
RawWriteChar(':');
return TAfterColonContext(*this);
}
-
+
TAfterColonContext TBuf::CompatWriteKeyWithoutQuotes(const TStringBuf& s) {
BeginKey();
Y_ASSERT(AllOf(s, [](char x) { return 'a' <= x && x <= 'z'; }));
@@ -194,44 +194,44 @@ namespace NJsonWriter {
EndValue();
return *this;
}
-
+
TBuf& TBuf::EndObject() {
CheckAndPop(JE_OBJECT);
EndValue();
return *this;
}
-
+
TValueContext TBuf::WriteString(const TStringBuf& s) {
// use the default escaping mode for this object
return WriteString(s, EscapeMode);
}
-
+
TValueContext TBuf::WriteString(const TStringBuf& s, EHtmlEscapeMode hem) {
BeginValue();
WriteBareString(s, hem);
EndValue();
return TValueContext(*this);
}
-
+
TValueContext TBuf::WriteNull() {
UnsafeWriteValue(TStringBuf("null"));
return TValueContext(*this);
}
-
+
TValueContext TBuf::WriteBool(bool b) {
constexpr TStringBuf trueVal = "true";
constexpr TStringBuf falseVal = "false";
UnsafeWriteValue(b ? trueVal : falseVal);
return TValueContext(*this);
}
-
+
TValueContext TBuf::WriteInt(int i) {
char buf[22]; // enough to hold any 64-bit number
size_t len = ToString(i, buf, sizeof(buf));
UnsafeWriteValue(buf, len);
return TValueContext(*this);
}
-
+
TValueContext TBuf::WriteLongLong(long long i) {
static_assert(sizeof(long long) <= 8, "expect sizeof(long long) <= 8");
char buf[22]; // enough to hold any 64-bit number
@@ -239,14 +239,14 @@ namespace NJsonWriter {
UnsafeWriteValue(buf, len);
return TValueContext(*this);
}
-
+
TValueContext TBuf::WriteULongLong(unsigned long long i) {
char buf[22]; // enough to hold any 64-bit number
size_t len = ToString(i, buf, sizeof(buf));
UnsafeWriteValue(buf, len);
return TValueContext(*this);
}
-
+
template <class TFloat>
TValueContext TBuf::WriteFloatImpl(TFloat f, EFloatToStringMode mode, int ndigits) {
char buf[512]; // enough to hold most floats, the same buffer is used in FloatToString implementation
@@ -271,7 +271,7 @@ namespace NJsonWriter {
TValueContext TBuf::WriteDouble(double f, EFloatToStringMode mode, int ndigits) {
return WriteFloatImpl(f, mode, ndigits);
}
-
+
namespace {
struct TFinder: public TCompactStrSpn {
inline TFinder()
@@ -306,12 +306,12 @@ namespace NJsonWriter {
}
UnsafeWriteRawBytes(b, e - b);
RawWriteChar('"');
- }
-
+ }
+
inline void TBuf::RawWriteChar(char c) {
Stream->Write(c);
}
-
+
void TBuf::WriteHexEscape(unsigned char c) {
Y_ASSERT(c < 0x80);
UnsafeWriteRawBytes("\\u00", 4);
@@ -319,13 +319,13 @@ namespace NJsonWriter {
RawWriteChar(hexDigits[(c & 0xf0) >> 4]);
RawWriteChar(hexDigits[(c & 0x0f)]);
}
-
+
#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) {
unsigned char c = *cur;
if (hem == HEM_ESCAPE_HTML) {
@@ -337,11 +337,11 @@ namespace NJsonWriter {
MATCH('&', "&amp;");
}
//for other characters, we fall through to the non-HTML-escaped part
- }
-
+ }
+
if (hem == HEM_RELAXED && c == '/')
return false;
-
+
if (hem != HEM_UNSAFE) {
switch (c) {
case '/':
@@ -356,16 +356,16 @@ namespace NJsonWriter {
return true;
}
// for other characters, fall through to the non-escaped part
- }
-
+ }
+
switch (c) {
- MATCH('"', "\\\"");
- MATCH('\\', "\\\\");
- MATCH('\b', "\\b");
- MATCH('\f', "\\f");
- MATCH('\n', "\\n");
- MATCH('\r', "\\r");
- MATCH('\t', "\\t");
+ MATCH('"', "\\\"");
+ MATCH('\\', "\\\\");
+ MATCH('\b', "\\b");
+ MATCH('\f', "\\f");
+ MATCH('\n', "\\n");
+ MATCH('\r', "\\r");
+ MATCH('\t', "\\t");
}
if (c < 0x20) {
UnsafeWriteRawBytes(beg, cur - beg);
@@ -374,14 +374,14 @@ namespace NJsonWriter {
}
return false;
- }
+ }
#undef MATCH
static bool LessStrPtr(const TString* a, const TString* b) {
return *a < *b;
}
-
+
TValueContext TBuf::WriteJsonValue(const NJson::TJsonValue* v, bool sortKeys, EFloatToStringMode mode, int ndigits) {
using namespace NJson;
switch (v->GetType()) {
@@ -411,7 +411,7 @@ namespace NJsonWriter {
WriteJsonValue(&it, sortKeys, mode, ndigits);
EndList();
break;
- }
+ }
case JSON_MAP: {
BeginObject();
const TJsonValue::TMapType& map = v->GetMap();
@@ -436,10 +436,10 @@ namespace NJsonWriter {
}
EndObject();
break;
- }
- }
+ }
+ }
return TValueContext(*this);
- }
+ }
TPairContext TBuf::UnsafeWritePair(const TStringBuf& s) {
if (Y_UNLIKELY(StackTop() != JE_OBJECT)) {
@@ -448,28 +448,28 @@ namespace NJsonWriter {
WriteComma();
UnsafeWriteRawBytes(s);
return TPairContext(*this);
- }
-
+ }
+
void TBuf::UnsafeWriteValue(const TStringBuf& s) {
BeginValue();
UnsafeWriteRawBytes(s);
EndValue();
- }
-
+ }
+
void TBuf::UnsafeWriteValue(const char* s, size_t len) {
BeginValue();
UnsafeWriteRawBytes(s, len);
EndValue();
}
-
+
void TBuf::UnsafeWriteRawBytes(const char* src, size_t len) {
Stream->Write(src, len);
}
-
+
void TBuf::UnsafeWriteRawBytes(const TStringBuf& s) {
UnsafeWriteRawBytes(s.data(), s.size());
}
-
+
const TString& TBuf::Str() const {
if (!StringStream) {
ythrow TError() << "JSON writer: Str() called "
@@ -480,7 +480,7 @@ namespace NJsonWriter {
}
return StringStream->Str();
}
-
+
void TBuf::FlushTo(IOutputStream* stream) {
if (!StringStream) {
ythrow TError() << "JSON writer: FlushTo() called "
@@ -488,7 +488,7 @@ namespace NJsonWriter {
}
stream->Write(StringStream->Str());
StringStream->Clear();
- }
+ }
TString WrapJsonToCallback(const TBuf& buf, TStringBuf callback) {
if (!callback) {
@@ -496,12 +496,12 @@ namespace NJsonWriter {
} else {
return TString::Join(callback, "(", buf.Str(), ")");
}
- }
-
+ }
+
TBufState TBuf::State() const {
return TBufState{NeedComma, NeedNewline, Stack};
- }
-
+ }
+
void TBuf::Reset(const TBufState& from) {
NeedComma = from.NeedComma;
NeedNewline = from.NeedNewline;
diff --git a/library/cpp/json/writer/json.h b/library/cpp/json/writer/json.h
index 0aae2531b9..f8e0783574 100644
--- a/library/cpp/json/writer/json.h
+++ b/library/cpp/json/writer/json.h
@@ -1,38 +1,38 @@
-#pragma once
-
-#include <util/generic/noncopyable.h>
-#include <util/generic/ptr.h>
+#pragma once
+
+#include <util/generic/noncopyable.h>
+#include <util/generic/ptr.h>
#include <util/generic/string.h>
-#include <util/generic/vector.h>
-#include <util/generic/yexception.h>
-#include <util/stream/str.h>
+#include <util/generic/vector.h>
+#include <util/generic/yexception.h>
+#include <util/stream/str.h>
#include <util/string/cast.h>
-
-namespace NJson {
- class TJsonValue;
-}
-
-namespace NJsonWriter {
+
+namespace NJson {
+ class TJsonValue;
+}
+
+namespace NJsonWriter {
enum EJsonEntity : ui8 {
- JE_OUTER_SPACE = 1,
- JE_LIST,
- JE_OBJECT,
- JE_PAIR,
- };
-
- enum EHtmlEscapeMode {
- HEM_ESCAPE_HTML = 1, // Use HTML escaping: &lt; &gt; &amp; \/
- HEM_DONT_ESCAPE_HTML, // Use JSON escaping: \u003C \u003E \u0026 \/
- HEM_RELAXED, // Use JSON escaping: \u003C \u003E \u0026 /
- HEM_UNSAFE, // Turn escaping off: < > & /
- };
-
- class TError: public yexception {};
-
- class TValueContext;
- class TPairContext;
- class TAfterColonContext;
-
+ JE_OUTER_SPACE = 1,
+ JE_LIST,
+ JE_OBJECT,
+ JE_PAIR,
+ };
+
+ enum EHtmlEscapeMode {
+ HEM_ESCAPE_HTML = 1, // Use HTML escaping: &lt; &gt; &amp; \/
+ HEM_DONT_ESCAPE_HTML, // Use JSON escaping: \u003C \u003E \u0026 \/
+ HEM_RELAXED, // Use JSON escaping: \u003C \u003E \u0026 /
+ HEM_UNSAFE, // Turn escaping off: < > & /
+ };
+
+ class TError: public yexception {};
+
+ class TValueContext;
+ class TPairContext;
+ class TAfterColonContext;
+
struct TBufState {
bool NeedComma;
bool NeedNewline;
@@ -40,102 +40,102 @@ namespace NJsonWriter {
};
class TBuf : TNonCopyable {
- public:
+ public:
TBuf(EHtmlEscapeMode mode = HEM_DONT_ESCAPE_HTML, IOutputStream* stream = nullptr);
-
+
TValueContext WriteString(const TStringBuf& s, EHtmlEscapeMode hem);
TValueContext WriteString(const TStringBuf& s);
- TValueContext WriteInt(int i);
+ TValueContext WriteInt(int i);
TValueContext WriteLongLong(long long i);
TValueContext WriteULongLong(unsigned long long i);
TValueContext WriteFloat(float f, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 6);
TValueContext WriteDouble(double f, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 10);
- TValueContext WriteBool(bool b);
- TValueContext WriteNull();
+ TValueContext WriteBool(bool b);
+ TValueContext WriteNull();
TValueContext WriteJsonValue(const NJson::TJsonValue* value, bool sortKeys = false, EFloatToStringMode mode = PREC_NDIGITS, int ndigits = 10);
-
- TValueContext BeginList();
- TBuf& EndList();
-
- TPairContext BeginObject();
+
+ TValueContext BeginList();
+ TBuf& EndList();
+
+ TPairContext BeginObject();
TAfterColonContext WriteKey(const TStringBuf& key, EHtmlEscapeMode hem);
TAfterColonContext WriteKey(const TStringBuf& key);
TAfterColonContext UnsafeWriteKey(const TStringBuf& key);
bool KeyExpected() const {
return Stack.back() == JE_OBJECT;
}
-
- //! deprecated, do not use in new code
+
+ //! deprecated, do not use in new code
TAfterColonContext CompatWriteKeyWithoutQuotes(const TStringBuf& key);
-
- TBuf& EndObject();
-
- /*** Indent the resulting JSON with spaces.
- * By default (spaces==0) no formatting is done. */
- TBuf& SetIndentSpaces(int spaces) {
- IndentSpaces = spaces;
- return *this;
- }
-
+
+ TBuf& EndObject();
+
+ /*** Indent the resulting JSON with spaces.
+ * 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) */
- TBuf& SetWriteNanAsString(bool writeNanAsString = true) {
+ TBuf& SetWriteNanAsString(bool writeNanAsString = true) {
WriteNanAsString = writeNanAsString;
- return *this;
+ return *this;
}
- /*** Return the string formed in the internal TStringStream.
- * You may only call it if the `stream' parameter was NULL
- * at construction time. */
+ /*** Return the string formed in the internal TStringStream.
+ * 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. */
+
+ /*** Dump and forget the string constructed so far.
+ * 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. */
+
+ /*** 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. */
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. */
+ 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. */
TPairContext UnsafeWritePair(const TStringBuf& s);
-
- /*** Copy the supplied string directly into the output stream. */
+
+ /*** Copy the supplied string directly into the output stream. */
void UnsafeWriteRawBytes(const TStringBuf& s);
- void UnsafeWriteRawBytes(const char* c, size_t len);
-
+ void UnsafeWriteRawBytes(const char* c, size_t len);
+
TBufState State() const;
void Reset(const TBufState& from);
void Reset(TBufState&& from);
- private:
- void BeginValue();
- void EndValue();
- void BeginKey();
- void RawWriteChar(char c);
+ private:
+ void BeginValue();
+ void EndValue();
+ void BeginKey();
+ void RawWriteChar(char c);
bool EscapedWriteChar(const char* b, const char* c, EHtmlEscapeMode hem);
void WriteBareString(const TStringBuf s, EHtmlEscapeMode hem);
- void WriteComma();
- void PrintIndentation(bool closing);
+ void WriteComma();
+ void PrintIndentation(bool closing);
void PrintWhitespaces(size_t count, bool prependWithNewLine);
- void WriteHexEscape(unsigned char c);
-
+ void WriteHexEscape(unsigned char c);
+
void StackPush(EJsonEntity e);
void StackPop();
void CheckAndPop(EJsonEntity e);
@@ -146,23 +146,23 @@ namespace NJsonWriter {
private:
IOutputStream* Stream;
- THolder<TStringStream> StringStream;
+ THolder<TStringStream> StringStream;
typedef TVector<const TString*> TKeys;
TKeys Keys;
TVector<EJsonEntity> Stack;
- bool NeedComma;
+ bool NeedComma;
bool NeedNewline;
- const EHtmlEscapeMode EscapeMode;
- int IndentSpaces;
+ const EHtmlEscapeMode EscapeMode;
+ int IndentSpaces;
bool WriteNanAsString;
- };
-
- // Please don't try to instantiate the classes declared below this point.
-
+ };
+
+ // Please don't try to instantiate the classes declared below this point.
+
template <typename TOutContext>
class TValueWriter {
- public:
+ public:
TOutContext WriteNull();
TOutContext WriteString(const TStringBuf&);
TOutContext WriteString(const TStringBuf& s, EHtmlEscapeMode hem);
@@ -177,82 +177,82 @@ namespace NJsonWriter {
TOutContext WriteJsonValue(const NJson::TJsonValue* value, bool sortKeys = false);
TOutContext UnsafeWriteValue(const TStringBuf&);
- TValueContext BeginList();
- TPairContext BeginObject();
-
- protected:
- TValueWriter(TBuf& buf)
- : Buf(buf)
+ TValueContext BeginList();
+ TPairContext BeginObject();
+
+ protected:
+ TValueWriter(TBuf& buf)
+ : Buf(buf)
{
}
- friend class TBuf;
-
- protected:
- TBuf& Buf;
- };
-
- class TValueContext: public TValueWriter<TValueContext> {
- public:
- TBuf& EndList() {
- return Buf.EndList();
- }
+ friend class TBuf;
+
+ protected:
+ TBuf& Buf;
+ };
+
+ class TValueContext: public TValueWriter<TValueContext> {
+ public:
+ TBuf& EndList() {
+ return Buf.EndList();
+ }
TString Str() const {
return Buf.Str();
}
- private:
- TValueContext(TBuf& buf)
- : TValueWriter<TValueContext>(buf)
+ private:
+ TValueContext(TBuf& buf)
+ : TValueWriter<TValueContext>(buf)
{
}
- friend class TBuf;
- friend class TValueWriter<TValueContext>;
- };
-
- class TAfterColonContext: public TValueWriter<TPairContext> {
- private:
+ friend class TBuf;
+ friend class TValueWriter<TValueContext>;
+ };
+
+ class TAfterColonContext: public TValueWriter<TPairContext> {
+ private:
TAfterColonContext(TBuf& iBuf)
: TValueWriter<TPairContext>(iBuf)
{
}
- friend class TBuf;
- friend class TPairContext;
- };
-
- class TPairContext {
- public:
+ friend class TBuf;
+ friend class TPairContext;
+ };
+
+ class TPairContext {
+ public:
TAfterColonContext WriteKey(const TStringBuf& s, EHtmlEscapeMode hem) {
- return Buf.WriteKey(s, hem);
- }
+ return Buf.WriteKey(s, hem);
+ }
TAfterColonContext WriteKey(const TStringBuf& s) {
- return Buf.WriteKey(s);
- }
+ return Buf.WriteKey(s);
+ }
TAfterColonContext UnsafeWriteKey(const TStringBuf& s) {
return Buf.UnsafeWriteKey(s);
}
TAfterColonContext CompatWriteKeyWithoutQuotes(const TStringBuf& s) {
- return Buf.CompatWriteKeyWithoutQuotes(s);
- }
+ return Buf.CompatWriteKeyWithoutQuotes(s);
+ }
TPairContext UnsafeWritePair(const TStringBuf& s) {
- return Buf.UnsafeWritePair(s);
- }
- TBuf& EndObject() {
- return Buf.EndObject();
- }
-
- private:
- TPairContext(TBuf& buf)
- : Buf(buf)
+ return Buf.UnsafeWritePair(s);
+ }
+ TBuf& EndObject() {
+ return Buf.EndObject();
+ }
+
+ private:
+ TPairContext(TBuf& buf)
+ : Buf(buf)
{
}
-
- friend class TBuf;
- friend class TValueWriter<TPairContext>;
-
- private:
- TBuf& Buf;
- };
-
+
+ friend class TBuf;
+ friend class TValueWriter<TPairContext>;
+
+ private:
+ TBuf& Buf;
+ };
+
#define JSON_VALUE_WRITER_WRAP(function, params, args) \
template <typename TOutContext> \
TOutContext TValueWriter<TOutContext>::function params { \
@@ -277,13 +277,13 @@ namespace NJsonWriter {
template <typename TOutContext>
TValueContext TValueWriter<TOutContext>::BeginList() {
- return Buf.BeginList();
- }
-
+ return Buf.BeginList();
+ }
+
template <typename TOutContext>
TPairContext TValueWriter<TOutContext>::BeginObject() {
- return Buf.BeginObject();
- }
+ return Buf.BeginObject();
+ }
TString WrapJsonToCallback(const TBuf& buf, TStringBuf callback);
-}
+}
diff --git a/library/cpp/json/writer/json_ut.cpp b/library/cpp/json/writer/json_ut.cpp
index 9980555683..d6842bcc6d 100644
--- a/library/cpp/json/writer/json_ut.cpp
+++ b/library/cpp/json/writer/json_ut.cpp
@@ -1,191 +1,191 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/system/sanitizers.h>
-
-#include "json.h"
+
+#include "json.h"
#include <library/cpp/json/json_value.h>
-
+
#include <limits>
Y_UNIT_TEST_SUITE(JsonWriter) {
Y_UNIT_TEST(Struct) {
- NJsonWriter::TBuf w;
- w.BeginList();
- w.BeginObject()
- .WriteKey("key")
- .WriteString("value")
- .UnsafeWritePair("\"xk\":13")
- .WriteKey("key2")
- .BeginList()
+ NJsonWriter::TBuf w;
+ w.BeginList();
+ w.BeginObject()
+ .WriteKey("key")
+ .WriteString("value")
+ .UnsafeWritePair("\"xk\":13")
+ .WriteKey("key2")
+ .BeginList()
.BeginObject()
.EndObject()
.BeginObject()
.EndObject()
- .EndList()
+ .EndList()
.EndObject();
- w.WriteInt(43);
- w.UnsafeWriteValue("\"x\"");
- w.WriteString("...");
- w.EndList();
- const char* exp = "[{\"key\":\"value\",\"xk\":13,\"key2\":[{},{}]},43,\"x\",\"...\"]";
- UNIT_ASSERT_EQUAL(w.Str(), exp);
- }
+ w.WriteInt(43);
+ w.UnsafeWriteValue("\"x\"");
+ w.WriteString("...");
+ w.EndList();
+ const char* exp = "[{\"key\":\"value\",\"xk\":13,\"key2\":[{},{}]},43,\"x\",\"...\"]";
+ UNIT_ASSERT_EQUAL(w.Str(), exp);
+ }
Y_UNIT_TEST(EscapedString) {
- NJsonWriter::TBuf w(NJsonWriter::HEM_ESCAPE_HTML);
- w.WriteString(" \n \r \t \007 \b \f ' <tag> &ent; \"txt\" ");
+ NJsonWriter::TBuf w(NJsonWriter::HEM_ESCAPE_HTML);
+ w.WriteString(" \n \r \t \007 \b \f ' <tag> &ent; \"txt\" ");
TString ws = w.Str();
- const char* exp = "\" \\n \\r \\t \\u0007 \\b \\f &#39; &lt;tag&gt; &amp;ent; &quot;txt&quot; \"";
- UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
- }
+ const char* exp = "\" \\n \\r \\t \\u0007 \\b \\f &#39; &lt;tag&gt; &amp;ent; &quot;txt&quot; \"";
+ UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
+ }
Y_UNIT_TEST(UnescapedString) {
- NJsonWriter::TBuf w;
- w.WriteString(" \n \r \t \b \f '; -- <tag> &ent; \"txt\"", NJsonWriter::HEM_DONT_ESCAPE_HTML);
+ NJsonWriter::TBuf w;
+ w.WriteString(" \n \r \t \b \f '; -- <tag> &ent; \"txt\"", NJsonWriter::HEM_DONT_ESCAPE_HTML);
TString ws = w.Str();
- const char* exp = "\" \\n \\r \\t \\b \\f \\u0027; -- \\u003Ctag\\u003E &ent; \\\"txt\\\"\"";
- UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
- }
+ const char* exp = "\" \\n \\r \\t \\b \\f \\u0027; -- \\u003Ctag\\u003E &ent; \\\"txt\\\"\"";
+ UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
+ }
Y_UNIT_TEST(UnescapedChaining) {
- NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
- w.UnsafeWriteRawBytes("(", 1);
- w.BeginList().WriteString("<>&'\\").BeginList();
- w.EndList().EndList();
+ NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
+ w.UnsafeWriteRawBytes("(", 1);
+ w.BeginList().WriteString("<>&'\\").BeginList();
+ w.EndList().EndList();
TString ws = w.Str();
- const char* exp = "([\"\\u003C\\u003E&\\u0027\\\\\",[]]";
- UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
- }
+ const char* exp = "([\"\\u003C\\u003E&\\u0027\\\\\",[]]";
+ UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
+ }
Y_UNIT_TEST(Utf8) {
TString ws = NJsonWriter::TBuf().WriteString("яЯ σΣ ש א").Str();
- const char* exp = "\"яЯ σΣ ש א\"";
- UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
- }
+ const char* exp = "\"яЯ σΣ ש א\"";
+ UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
+ }
Y_UNIT_TEST(WrongObject) {
- NJsonWriter::TBuf w;
- w.BeginObject();
- UNIT_ASSERT_EXCEPTION(w.WriteString("hehe"), NJsonWriter::TError);
- }
+ NJsonWriter::TBuf w;
+ w.BeginObject();
+ UNIT_ASSERT_EXCEPTION(w.WriteString("hehe"), NJsonWriter::TError);
+ }
Y_UNIT_TEST(WrongList) {
- NJsonWriter::TBuf w;
- w.BeginList();
- UNIT_ASSERT_EXCEPTION(w.WriteKey("hehe"), NJsonWriter::TError);
- }
+ NJsonWriter::TBuf w;
+ w.BeginList();
+ UNIT_ASSERT_EXCEPTION(w.WriteKey("hehe"), NJsonWriter::TError);
+ }
Y_UNIT_TEST(Incomplete) {
- NJsonWriter::TBuf w;
- w.BeginList();
- UNIT_ASSERT_EXCEPTION(w.Str(), NJsonWriter::TError);
- }
+ NJsonWriter::TBuf w;
+ w.BeginList();
+ UNIT_ASSERT_EXCEPTION(w.Str(), NJsonWriter::TError);
+ }
Y_UNIT_TEST(BareKey) {
- NJsonWriter::TBuf w;
- w.BeginObject()
+ NJsonWriter::TBuf w;
+ w.BeginObject()
.CompatWriteKeyWithoutQuotes("p")
.WriteInt(1)
.CompatWriteKeyWithoutQuotes("n")
.WriteInt(0)
.EndObject();
TString ws = w.Str();
- const char* exp = "{p:1,n:0}";
- UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
- }
+ const char* exp = "{p:1,n:0}";
+ UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
+ }
Y_UNIT_TEST(UnescapedStringInObject) {
- NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
- w.BeginObject().WriteKey("key").WriteString("</&>'").EndObject();
+ NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
+ w.BeginObject().WriteKey("key").WriteString("</&>'").EndObject();
TString ws = w.Str();
- const char* exp = "{\"key\":\"\\u003C\\/&\\u003E\\u0027\"}";
- UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
- }
+ const char* exp = "{\"key\":\"\\u003C\\/&\\u003E\\u0027\"}";
+ UNIT_ASSERT_STRINGS_EQUAL(ws.c_str(), exp);
+ }
Y_UNIT_TEST(ForeignStreamStr) {
- NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML, &Cerr);
- UNIT_ASSERT_EXCEPTION(w.Str(), NJsonWriter::TError);
- }
+ NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML, &Cerr);
+ UNIT_ASSERT_EXCEPTION(w.Str(), NJsonWriter::TError);
+ }
Y_UNIT_TEST(ForeignStreamValue) {
- TStringStream ss;
- NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML, &ss);
- w.WriteInt(1543);
- UNIT_ASSERT_STRINGS_EQUAL(ss.Str(), "1543");
- }
+ TStringStream ss;
+ NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML, &ss);
+ w.WriteInt(1543);
+ UNIT_ASSERT_STRINGS_EQUAL(ss.Str(), "1543");
+ }
Y_UNIT_TEST(Indentation) {
- NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
- w.SetIndentSpaces(2);
- w.BeginList()
- .WriteInt(1)
- .WriteString("hello")
- .BeginObject()
+ NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
+ w.SetIndentSpaces(2);
+ w.BeginList()
+ .WriteInt(1)
+ .WriteString("hello")
+ .BeginObject()
.WriteKey("abc")
.WriteInt(3)
.WriteKey("def")
.WriteInt(4)
- .EndObject()
+ .EndObject()
.EndList();
- const char* exp = "[\n"
- " 1,\n"
- " \"hello\",\n"
- " {\n"
+ const char* exp = "[\n"
+ " 1,\n"
+ " \"hello\",\n"
+ " {\n"
" \"abc\":3,\n"
" \"def\":4\n"
- " }\n"
- "]";
- UNIT_ASSERT_STRINGS_EQUAL(exp, w.Str());
- }
+ " }\n"
+ "]";
+ UNIT_ASSERT_STRINGS_EQUAL(exp, w.Str());
+ }
Y_UNIT_TEST(WriteJsonValue) {
- using namespace NJson;
- TJsonValue val;
- val.AppendValue(1);
- val.AppendValue("2");
- val.AppendValue(3.5);
- TJsonValue obj;
- obj.InsertValue("key", TJsonValue("value"));
-
- val.AppendValue(obj);
- val.AppendValue(TJsonValue(JSON_NULL));
-
- NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
- w.WriteJsonValue(&val);
-
- const char exp[] = "[1,\"2\",3.5,{\"key\":\"value\"},null]";
- UNIT_ASSERT_STRINGS_EQUAL(exp, w.Str());
- }
+ using namespace NJson;
+ TJsonValue val;
+ val.AppendValue(1);
+ val.AppendValue("2");
+ val.AppendValue(3.5);
+ TJsonValue obj;
+ obj.InsertValue("key", TJsonValue("value"));
+
+ val.AppendValue(obj);
+ val.AppendValue(TJsonValue(JSON_NULL));
+
+ NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
+ w.WriteJsonValue(&val);
+
+ const char exp[] = "[1,\"2\",3.5,{\"key\":\"value\"},null]";
+ UNIT_ASSERT_STRINGS_EQUAL(exp, w.Str());
+ }
Y_UNIT_TEST(WriteJsonValueSorted) {
- using namespace NJson;
- TJsonValue val;
- val.InsertValue("1", TJsonValue(1));
- val.InsertValue("2", TJsonValue(2));
-
- TJsonValue obj;
- obj.InsertValue("zero", TJsonValue(0));
- obj.InsertValue("succ", TJsonValue(1));
- val.InsertValue("0", obj);
-
- NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
- w.WriteJsonValue(&val, true);
-
- const char exp[] = "{\"0\":{\"succ\":1,\"zero\":0},\"1\":1,\"2\":2}";
- UNIT_ASSERT_STRINGS_EQUAL(exp, w.Str());
- }
+ using namespace NJson;
+ TJsonValue val;
+ val.InsertValue("1", TJsonValue(1));
+ val.InsertValue("2", TJsonValue(2));
+
+ TJsonValue obj;
+ obj.InsertValue("zero", TJsonValue(0));
+ obj.InsertValue("succ", TJsonValue(1));
+ val.InsertValue("0", obj);
+
+ NJsonWriter::TBuf w(NJsonWriter::HEM_DONT_ESCAPE_HTML);
+ w.WriteJsonValue(&val, true);
+
+ const char exp[] = "{\"0\":{\"succ\":1,\"zero\":0},\"1\":1,\"2\":2}";
+ UNIT_ASSERT_STRINGS_EQUAL(exp, w.Str());
+ }
Y_UNIT_TEST(Unescaped) {
- NJsonWriter::TBuf buf(NJsonWriter::HEM_UNSAFE);
- buf.WriteString("</security>'");
- UNIT_ASSERT_STRINGS_EQUAL("\"</security>'\"", buf.Str());
- }
+ NJsonWriter::TBuf buf(NJsonWriter::HEM_UNSAFE);
+ buf.WriteString("</security>'");
+ UNIT_ASSERT_STRINGS_EQUAL("\"</security>'\"", buf.Str());
+ }
Y_UNIT_TEST(LittleBobbyJsonp) {
- NJsonWriter::TBuf buf;
- buf.WriteString("hello\xe2\x80\xa8\xe2\x80\xa9stranger");
- UNIT_ASSERT_STRINGS_EQUAL("\"hello\\u2028\\u2029stranger\"", buf.Str());
- }
+ NJsonWriter::TBuf buf;
+ buf.WriteString("hello\xe2\x80\xa8\xe2\x80\xa9stranger");
+ UNIT_ASSERT_STRINGS_EQUAL("\"hello\\u2028\\u2029stranger\"", buf.Str());
+ }
Y_UNIT_TEST(LittleBobbyInvalid) {
- NJsonWriter::TBuf buf;
- TStringBuf incomplete("\xe2\x80\xa8", 2);
- buf.WriteString(incomplete);
- // garbage in - garbage out
- UNIT_ASSERT_STRINGS_EQUAL("\"\xe2\x80\"", buf.Str());
- }
+ NJsonWriter::TBuf buf;
+ TStringBuf incomplete("\xe2\x80\xa8", 2);
+ buf.WriteString(incomplete);
+ // garbage in - garbage out
+ UNIT_ASSERT_STRINGS_EQUAL("\"\xe2\x80\"", buf.Str());
+ }
Y_UNIT_TEST(OverlyZealous) {
- NJsonWriter::TBuf buf;
- buf.WriteString("—");
- UNIT_ASSERT_STRINGS_EQUAL("\"—\"", buf.Str());
- }
+ NJsonWriter::TBuf buf;
+ buf.WriteString("—");
+ UNIT_ASSERT_STRINGS_EQUAL("\"—\"", buf.Str());
+ }
Y_UNIT_TEST(RelaxedEscaping) {
- NJsonWriter::TBuf buf(NJsonWriter::HEM_RELAXED);
- buf.WriteString("</>");
- UNIT_ASSERT_STRINGS_EQUAL("\"\\u003C/\\u003E\"", buf.Str());
- }
+ NJsonWriter::TBuf buf(NJsonWriter::HEM_RELAXED);
+ buf.WriteString("</>");
+ UNIT_ASSERT_STRINGS_EQUAL("\"\\u003C/\\u003E\"", buf.Str());
+ }
Y_UNIT_TEST(FloatFormatting) {
NJsonWriter::TBuf buf(NJsonWriter::HEM_DONT_ESCAPE_HTML);
@@ -304,4 +304,4 @@ Y_UNIT_TEST_SUITE(JsonWriter) {
// doesn't really matter
UNIT_ASSERT(!p.empty());
}
-}
+}
diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp
index c61e8d1dc4..26fa35eed3 100644
--- a/library/cpp/json/writer/json_value.cpp
+++ b/library/cpp/json/writer/json_value.cpp
@@ -1,5 +1,5 @@
#include "json_value.h"
-#include "json.h"
+#include "json.h"
#include <util/generic/ymath.h>
#include <util/generic/ylimits.h>
@@ -161,7 +161,7 @@ namespace NJson {
Value.Double = value;
}
- TJsonValue::TJsonValue(TString value) {
+ TJsonValue::TJsonValue(TString value) {
SetType(JSON_STRING);
Value.String = std::move(value);
}
@@ -1100,6 +1100,6 @@ namespace NJson {
template <>
void Out<NJson::TJsonValue>(IOutputStream& out, const NJson::TJsonValue& v) {
- NJsonWriter::TBuf buf(NJsonWriter::HEM_DONT_ESCAPE_HTML, &out);
- buf.WriteJsonValue(&v);
+ NJsonWriter::TBuf buf(NJsonWriter::HEM_DONT_ESCAPE_HTML, &out);
+ buf.WriteJsonValue(&v);
}
diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h
index 3f0f50bc4c..b24029b8bb 100644
--- a/library/cpp/json/writer/json_value.h
+++ b/library/cpp/json/writer/json_value.h
@@ -48,7 +48,7 @@ namespace NJson {
TJsonValue(long long value) noexcept;
TJsonValue(unsigned long long value) noexcept;
TJsonValue(double value) noexcept;
- TJsonValue(TString value);
+ TJsonValue(TString value);
TJsonValue(const char* value);
template <class T>
TJsonValue(const T*) = delete;
diff --git a/library/cpp/json/writer/ya.make b/library/cpp/json/writer/ya.make
index 3989ff3504..cfbab3c818 100644
--- a/library/cpp/json/writer/ya.make
+++ b/library/cpp/json/writer/ya.make
@@ -1,4 +1,4 @@
-LIBRARY()
+LIBRARY()
OWNER(
mvel
@@ -9,12 +9,12 @@ OWNER(
PEERDIR(
library/cpp/json/common
)
-
-SRCS(
- json_value.cpp
- json.cpp
-)
-
+
+SRCS(
+ json_value.cpp
+ json.cpp
+)
+
GENERATE_ENUM_SERIALIZATION(json_value.h)
-END()
+END()
diff --git a/library/cpp/packers/region_packer.h b/library/cpp/packers/region_packer.h
index 2c661cb5bc..0e82475531 100644
--- a/library/cpp/packers/region_packer.h
+++ b/library/cpp/packers/region_packer.h
@@ -1,18 +1,18 @@
#pragma once
-
+
#include "packers.h"
#include <util/generic/array_ref.h>
-
-// Stores an array of PODs in the trie (copying them with memcpy).
-// Byte order and alignment are your problem.
-
+
+// Stores an array of PODs in the trie (copying them with memcpy).
+// Byte order and alignment are your problem.
+
template <class TRecord>
class TRegionPacker {
public:
typedef TArrayRef<TRecord> TRecords;
- void UnpackLeaf(const char* p, TRecords& result) const {
+ void UnpackLeaf(const char* p, TRecords& result) const {
size_t len;
NPackers::TIntegralPacker<size_t>().UnpackLeaf(p, len);
size_t start = NPackers::TIntegralPacker<size_t>().SkipLeaf(p);
@@ -32,7 +32,7 @@ public:
return NPackers::TIntegralPacker<size_t>().MeasureLeaf(len) + len * sizeof(TRecord);
}
- size_t SkipLeaf(const char* p) const {
+ size_t SkipLeaf(const char* p) const {
size_t result = NPackers::TIntegralPacker<size_t>().SkipLeaf(p);
size_t len;
NPackers::TIntegralPacker<size_t>().UnpackLeaf(p, len);
diff --git a/library/cpp/packers/ut/region_packer_ut.cpp b/library/cpp/packers/ut/region_packer_ut.cpp
index 0cb08ccf65..0da6a8b773 100644
--- a/library/cpp/packers/ut/region_packer_ut.cpp
+++ b/library/cpp/packers/ut/region_packer_ut.cpp
@@ -1,40 +1,40 @@
-#include "region_packer.h"
+#include "region_packer.h"
#include <library/cpp/testing/unittest/registar.h>
-
-template <typename TValue>
-void TestPacker() {
- TValue values[] = {1, 2, 3, 42};
+
+template <typename TValue>
+void TestPacker() {
+ TValue values[] = {1, 2, 3, 42};
TString buffer;
-
- TRegionPacker<TValue> p;
-
+
+ TRegionPacker<TValue> p;
+
using TValues = TArrayRef<TValue>;
TValues valueRegion = TValues(values, Y_ARRAY_SIZE(values));
- size_t sz = p.MeasureLeaf(valueRegion);
- UNIT_ASSERT_VALUES_EQUAL(sz, 1 + sizeof(values));
-
- buffer.resize(sz);
- p.PackLeaf(buffer.begin(), valueRegion, sz);
- UNIT_ASSERT_VALUES_EQUAL(buffer[0], 4);
-
+ size_t sz = p.MeasureLeaf(valueRegion);
+ UNIT_ASSERT_VALUES_EQUAL(sz, 1 + sizeof(values));
+
+ buffer.resize(sz);
+ p.PackLeaf(buffer.begin(), valueRegion, sz);
+ UNIT_ASSERT_VALUES_EQUAL(buffer[0], 4);
+
p.UnpackLeaf(buffer.data(), valueRegion);
UNIT_ASSERT_EQUAL(valueRegion.data(), (const TValue*)(buffer.begin() + 1));
UNIT_ASSERT_EQUAL(valueRegion.size(), Y_ARRAY_SIZE(values));
UNIT_ASSERT_EQUAL(0, memcmp(values, valueRegion.data(), sizeof(values)));
-}
-
+}
+
Y_UNIT_TEST_SUITE(RegionPacker) {
Y_UNIT_TEST(Test0) {
- TestPacker<char>();
- TestPacker<signed char>();
- TestPacker<unsigned char>();
- TestPacker<i8>();
- TestPacker<ui8>();
- TestPacker<i16>();
- TestPacker<ui16>();
- TestPacker<i32>();
- TestPacker<ui32>();
- TestPacker<i64>();
- TestPacker<ui64>();
- }
-}
+ TestPacker<char>();
+ TestPacker<signed char>();
+ TestPacker<unsigned char>();
+ TestPacker<i8>();
+ TestPacker<ui8>();
+ TestPacker<i16>();
+ TestPacker<ui16>();
+ TestPacker<i32>();
+ TestPacker<ui32>();
+ TestPacker<i64>();
+ TestPacker<ui64>();
+ }
+}
diff --git a/library/cpp/protobuf/json/json2proto.h b/library/cpp/protobuf/json/json2proto.h
index 4c33498dfa..fc2d21cc18 100644
--- a/library/cpp/protobuf/json/json2proto.h
+++ b/library/cpp/protobuf/json/json2proto.h
@@ -8,7 +8,7 @@
#include <util/stream/input.h>
#include <util/stream/str.h>
-#include <util/stream/mem.h>
+#include <util/stream/mem.h>
namespace google {
namespace protobuf {
@@ -218,5 +218,5 @@ namespace NProtobufJson {
T Json2Proto(const char* ptr, const TJson2ProtoConfig& config = TJson2ProtoConfig()) {
return Json2Proto<T>(TStringBuf(ptr), config);
}
-
+
}
diff --git a/library/cpp/sighandler/async_signals_handler.cpp b/library/cpp/sighandler/async_signals_handler.cpp
index 00ce1c18fb..f1b5a09c43 100644
--- a/library/cpp/sighandler/async_signals_handler.cpp
+++ b/library/cpp/sighandler/async_signals_handler.cpp
@@ -215,14 +215,14 @@ void SetAsyncSignalHandler(int, TAutoPtr<TEventHandler>) {
#endif
namespace {
- template <typename TFunc>
- class TFunctionEventHandler: public TEventHandler {
- TFunc Func;
+ template <typename TFunc>
+ class TFunctionEventHandler: public TEventHandler {
+ TFunc Func;
public:
- TFunctionEventHandler(TFunc func) {
- if (func)
- Func = func;
+ TFunctionEventHandler(TFunc func) {
+ if (func)
+ Func = func;
}
int Handle(int signum) override {
@@ -238,8 +238,8 @@ namespace {
void SetAsyncSignalHandler(int signum, void (*handler)(int)) {
SetAsyncSignalHandler(signum, new TFunctionEventHandler<void (*)(int)>(handler));
}
-
+
void SetAsyncSignalFunction(int signum, std::function<void(int)> func) {
typedef std::function<void(int)> TFunc;
- SetAsyncSignalHandler(signum, new TFunctionEventHandler<TFunc>(func));
-}
+ SetAsyncSignalHandler(signum, new TFunctionEventHandler<TFunc>(func));
+}
diff --git a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h
index 8a240bfed8..5c8e4adb14 100644
--- a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h
+++ b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff.h
@@ -141,16 +141,16 @@ namespace NLevenshtein {
template <class TStringType>
size_t Distance(const TStringType& str1, const TStringType& str2) {
- TEditChain editChain;
- GetEditChain(str1, str2, editChain);
- size_t result = 0;
- for (auto edit : editChain) {
- if (IsImportantEditMove(edit))
- result++;
- }
- return result;
- }
-
+ TEditChain editChain;
+ GetEditChain(str1, str2, editChain);
+ size_t result = 0;
+ for (auto edit : editChain) {
+ if (IsImportantEditMove(edit))
+ result++;
+ }
+ return result;
+ }
+
/// Calculates substrings to be replaced for str1->str2 transformation
struct TReplacement {
int CorrectOffset, CorrectLength, MisspelledOffset, MisspelledLength;
diff --git a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp
index cf0f78637f..c5f2165854 100644
--- a/library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp
+++ b/library/cpp/string_utils/levenshtein_diff/levenshtein_diff_ut.cpp
@@ -1,7 +1,7 @@
#include "levenshtein_diff.h"
-
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#include <util/generic/string.h>
namespace {
@@ -28,8 +28,8 @@ Y_UNIT_TEST_SUITE(Levenstein) {
Y_UNIT_TEST(Distance) {
UNIT_ASSERT_VALUES_EQUAL(NLevenshtein::Distance(TStringBuf("hello"), TStringBuf("hulloah")), 3);
UNIT_ASSERT_VALUES_EQUAL(NLevenshtein::Distance(TStringBuf("yeoman"), TStringBuf("yo man")), 2);
- }
-}
+ }
+}
Y_UNIT_TEST_SUITE(WeightedLevenstein) {
Y_UNIT_TEST(EqualStrings) {
diff --git a/library/cpp/string_utils/levenshtein_diff/ut/ya.make b/library/cpp/string_utils/levenshtein_diff/ut/ya.make
index a3b9b8fea5..79130d6264 100644
--- a/library/cpp/string_utils/levenshtein_diff/ut/ya.make
+++ b/library/cpp/string_utils/levenshtein_diff/ut/ya.make
@@ -1,9 +1,9 @@
UNITTEST_FOR(library/cpp/string_utils/levenshtein_diff)
-OWNER(myltsev)
-
+OWNER(myltsev)
+
SRCS(
levenshtein_diff_ut.cpp
)
-
-END()
+
+END()
diff --git a/library/cpp/string_utils/ya.make b/library/cpp/string_utils/ya.make
index cd731bda95..c802c438dc 100644
--- a/library/cpp/string_utils/ya.make
+++ b/library/cpp/string_utils/ya.make
@@ -1,4 +1,4 @@
-RECURSE(
+RECURSE(
ascii_encode
ascii_encode/ut
base64
@@ -33,5 +33,5 @@ RECURSE(
tskv_format/fuzz
url
url/ut
- ztstrbuf
-)
+ ztstrbuf
+)
diff --git a/library/cpp/string_utils/ztstrbuf/ya.make b/library/cpp/string_utils/ztstrbuf/ya.make
index 28b3f32f58..10bdad091f 100644
--- a/library/cpp/string_utils/ztstrbuf/ya.make
+++ b/library/cpp/string_utils/ztstrbuf/ya.make
@@ -1,9 +1,9 @@
-LIBRARY()
-
-OWNER(myltsev)
-
-SRCS(
- ztstrbuf.cpp
-)
-
-END()
+LIBRARY()
+
+OWNER(myltsev)
+
+SRCS(
+ ztstrbuf.cpp
+)
+
+END()
diff --git a/library/cpp/string_utils/ztstrbuf/ztstrbuf.cpp b/library/cpp/string_utils/ztstrbuf/ztstrbuf.cpp
index 4a7269ff4a..98f6cead1c 100644
--- a/library/cpp/string_utils/ztstrbuf/ztstrbuf.cpp
+++ b/library/cpp/string_utils/ztstrbuf/ztstrbuf.cpp
@@ -1,8 +1,8 @@
-#include "ztstrbuf.h"
-
-#include <util/stream/output.h>
-
-template <>
-void Out<TZtStringBuf>(IOutputStream& os, const TZtStringBuf& sb) {
- os << static_cast<const TStringBuf&>(sb);
-}
+#include "ztstrbuf.h"
+
+#include <util/stream/output.h>
+
+template <>
+void Out<TZtStringBuf>(IOutputStream& os, const TZtStringBuf& sb) {
+ os << static_cast<const TStringBuf&>(sb);
+}
diff --git a/library/cpp/string_utils/ztstrbuf/ztstrbuf.h b/library/cpp/string_utils/ztstrbuf/ztstrbuf.h
index 5fab768d8c..04c509bcc5 100644
--- a/library/cpp/string_utils/ztstrbuf/ztstrbuf.h
+++ b/library/cpp/string_utils/ztstrbuf/ztstrbuf.h
@@ -1,36 +1,36 @@
-#pragma once
-
-#include <util/generic/strbuf.h>
+#pragma once
+
+#include <util/generic/strbuf.h>
#include <util/generic/string.h>
-
-/*
- * Zero-terminated string view.
- *
- * Has a c_str() for use with system/cstdlib calls (like TString)
- * but can be constructed from a string literal or command-line arg
- * without memory allocation (like TStringBuf).
- *
- * Use it to reference filenames, thread names, string formats etc.
- */
-
-class TZtStringBuf: public TStringBuf {
-public:
- TZtStringBuf(const char* s)
- : TStringBuf(s)
- {
- }
-
- TZtStringBuf(const TString& s)
- : TStringBuf(s)
- {
- }
-
- TZtStringBuf()
- : TZtStringBuf(TString{})
- {
- }
-
- const char* c_str() const {
- return data();
- }
-};
+
+/*
+ * Zero-terminated string view.
+ *
+ * Has a c_str() for use with system/cstdlib calls (like TString)
+ * but can be constructed from a string literal or command-line arg
+ * without memory allocation (like TStringBuf).
+ *
+ * Use it to reference filenames, thread names, string formats etc.
+ */
+
+class TZtStringBuf: public TStringBuf {
+public:
+ TZtStringBuf(const char* s)
+ : TStringBuf(s)
+ {
+ }
+
+ TZtStringBuf(const TString& s)
+ : TStringBuf(s)
+ {
+ }
+
+ TZtStringBuf()
+ : TZtStringBuf(TString{})
+ {
+ }
+
+ const char* c_str() const {
+ return data();
+ }
+};
diff --git a/library/cpp/xml/document/README b/library/cpp/xml/document/README
index b2649523d8..c7396aec30 100644
--- a/library/cpp/xml/document/README
+++ b/library/cpp/xml/document/README
@@ -1,20 +1,20 @@
-A wrapper around the DOM interface of libxml2.
-
-The standard way to use it is as follows:
-
+A wrapper around the DOM interface of libxml2.
+
+The standard way to use it is as follows:
+
#include <library/cpp/xml/document/xml-document.h>
- ...
-
- // open a document
- NXml::TDocument xml("filename.xml");
-
- // get a nodeset from an XPath query
- NXml::TConstNodes nodes = xml.Root().Nodes("xpath/expression/here");
-
- // iterate over the nodeset
- for (size_t i = 0; i < nodes.size(); ++i) {
+ ...
+
+ // open a document
+ NXml::TDocument xml("filename.xml");
+
+ // get a nodeset from an XPath query
+ NXml::TConstNodes nodes = xml.Root().Nodes("xpath/expression/here");
+
+ // iterate over the nodeset
+ for (size_t i = 0; i < nodes.size(); ++i) {
using namespace NXml;
- TConstNode& node = nodes[i];
+ TConstNode& node = nodes[i];
// query node
TString name = node.Name();
TString lang = node.Attr<TString>("lang");
@@ -26,8 +26,8 @@ The standard way to use it is as follows:
node.SetAttr("x", 2);
node.SetValue(5);
node.AddText(" apples");
- }
-
+ }
+
// edit documents with copy-paste
NXml::TDocument xml2("<xpath><node/></xpath>", NXml::TDocument::String);
NXml::TNode place = xml2.Root().Node("xpath/node");
@@ -39,4 +39,4 @@ The standard way to use it is as follows:
TString modifiedDoc = xml2.ToString("ISO-8559-1");
-See xml-document_ut.cpp for more examples.
+See xml-document_ut.cpp for more examples.
diff --git a/library/cpp/xml/document/libxml-guards.h b/library/cpp/xml/document/libxml-guards.h
index 4188cecff1..619ca23ce7 100644
--- a/library/cpp/xml/document/libxml-guards.h
+++ b/library/cpp/xml/document/libxml-guards.h
@@ -2,10 +2,10 @@
#include <library/cpp/xml/init/ptr.h>
#include <util/generic/ptr.h>
-#include <libxml/xmlstring.h>
-#include <libxml/tree.h>
-#include <libxml/xpath.h>
-#include <libxml/uri.h>
+#include <libxml/xmlstring.h>
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+#include <libxml/uri.h>
#include <libxml/xmlsave.h>
namespace NXml {
@@ -36,15 +36,15 @@ namespace NXml {
}
- typedef TxmlXPathContextPtr TXPathContextPtr;
- typedef TxmlXPathObjectPtr TXPathObjectPtr;
+ typedef TxmlXPathContextPtr TXPathContextPtr;
+ typedef TxmlXPathObjectPtr TXPathObjectPtr;
typedef TAutoPtr<char, NDetail::TSignedCharPtrTraits> TSignedCharPtr;
typedef TAutoPtr<xmlChar, NDetail::TCharPtrTraits> TCharPtr;
typedef TxmlDocHolder TDocHolder;
- typedef TxmlURIPtr TURIPtr;
- typedef TxmlNodePtr TNodePtr;
+ typedef TxmlURIPtr TURIPtr;
+ typedef TxmlNodePtr TNodePtr;
typedef TAutoPtr<xmlOutputBuffer, NDetail::TOutputBufferPtrTraits> TOutputBufferPtr;
- typedef TxmlParserCtxtPtr TParserCtxtPtr;
+ typedef TxmlParserCtxtPtr TParserCtxtPtr;
typedef TAutoPtr<xmlSaveCtxt, NDetail::TSaveCtxtPtrTraits> TSaveCtxtPtr;
}
diff --git a/library/cpp/xml/document/node-attr.h b/library/cpp/xml/document/node-attr.h
index 6e74403943..2642eb96f9 100644
--- a/library/cpp/xml/document/node-attr.h
+++ b/library/cpp/xml/document/node-attr.h
@@ -1,24 +1,24 @@
#pragma once
#include "xml-document-decl.h"
-#include "libxml-guards.h"
+#include "libxml-guards.h"
#include <util/stream/str.h>
#include <util/string/cast.h>
namespace NXml {
#define THROW(x, y) ythrow yexception() << #x << ": " << y
- // libxml defines unsigned char -> xmlChar,
- // and all functions use xmlChar.
+ // libxml defines unsigned char -> xmlChar,
+ // and all functions use xmlChar.
inline static const char* CAST2CHAR(const xmlChar* x) {
return reinterpret_cast<const char*>(x);
}
inline static const xmlChar* XMLCHAR(const char* x) {
return reinterpret_cast<const xmlChar*>(x);
}
-
+
template <class T>
- void TNode::AttrInternal(TCharPtr& value, T& res, TStringBuf errContext) const {
+ void TNode::AttrInternal(TCharPtr& value, T& res, TStringBuf errContext) const {
try {
res = FromString<T>(CAST2CHAR(value.Get()));
} catch (TFromStringException&) {
@@ -27,16 +27,16 @@ namespace NXml {
}
template <>
- inline void TNode::AttrInternal(TCharPtr& value, TString& res, TStringBuf /*errContext*/) const {
+ inline void TNode::AttrInternal(TCharPtr& value, TString& res, TStringBuf /*errContext*/) const {
TString tmp(CAST2CHAR(value.Get()));
res.swap(tmp);
}
template <class T>
- T TNode::Attr(TZtStringBuf name) const {
- TCharPtr value(xmlGetProp(NodePointer, XMLCHAR(name.c_str())));
+ T TNode::Attr(TZtStringBuf name) const {
+ TCharPtr value(xmlGetProp(NodePointer, XMLCHAR(name.c_str())));
if (!value) {
- THROW(AttributeNotFound, Path() << "@" << name);
+ THROW(AttributeNotFound, Path() << "@" << name);
}
T t;
@@ -45,8 +45,8 @@ namespace NXml {
}
template <class T>
- T TNode::Attr(TZtStringBuf name, const T& defvalue) const {
- TCharPtr attr(xmlGetProp(NodePointer, XMLCHAR(name.c_str())));
+ T TNode::Attr(TZtStringBuf name, const T& defvalue) const {
+ TCharPtr attr(xmlGetProp(NodePointer, XMLCHAR(name.c_str())));
if (!attr) {
return defvalue;
}
@@ -57,18 +57,18 @@ namespace NXml {
}
template <class T>
- void TNode::Attr(TZtStringBuf name, T& value) const {
- TCharPtr attr(xmlGetProp(NodePointer, XMLCHAR(name.c_str())));
+ void TNode::Attr(TZtStringBuf name, T& value) const {
+ TCharPtr attr(xmlGetProp(NodePointer, XMLCHAR(name.c_str())));
if (!attr) {
- THROW(AttributeNotFound, Path() << name);
+ THROW(AttributeNotFound, Path() << name);
}
AttrInternal(attr, value, name);
}
template <class T>
- void TNode::Attr(TZtStringBuf name, T& value, const T& defvalue) const {
- TCharPtr attr(xmlGetProp(NodePointer, XMLCHAR(name.c_str())));
+ void TNode::Attr(TZtStringBuf name, T& value, const T& defvalue) const {
+ TCharPtr attr(xmlGetProp(NodePointer, XMLCHAR(name.c_str())));
if (!attr) {
value = defvalue;
@@ -80,10 +80,10 @@ namespace NXml {
template <class T>
T TNode::Value() const {
if (!NodePointer || xmlIsBlankNode(NodePointer)) {
- THROW(NodeIsBlank, Path());
+ THROW(NodeIsBlank, Path());
}
- TCharPtr val(xmlNodeGetContent(NodePointer));
+ TCharPtr val(xmlNodeGetContent(NodePointer));
T t;
AttrInternal(val, t, this->Name());
return t;
@@ -95,26 +95,26 @@ namespace NXml {
return defvalue;
}
- TCharPtr val(xmlNodeGetContent(NodePointer));
+ TCharPtr val(xmlNodeGetContent(NodePointer));
T t;
AttrInternal(val, t, this->Name());
return t;
}
template <class T>
- typename std::enable_if<!std::is_convertible_v<T, TStringBuf>, void>::type
- TNode::SetValue(const T& value) {
+ typename std::enable_if<!std::is_convertible_v<T, TStringBuf>, void>::type
+ TNode::SetValue(const T& value) {
TStringStream ss;
ss << value;
- SetValue(ss.Str());
- }
-
- inline void TNode::SetValue(TStringBuf value) {
+ SetValue(ss.Str());
+ }
+
+ inline void TNode::SetValue(TStringBuf value) {
xmlNodeSetContent(NodePointer, XMLCHAR(""));
- xmlNodeAddContentLen(NodePointer, XMLCHAR(value.data()), value.Size());
+ xmlNodeAddContentLen(NodePointer, XMLCHAR(value.data()), value.Size());
}
- inline void TNode::SetAttr(TZtStringBuf name, TZtStringBuf value) {
+ inline void TNode::SetAttr(TZtStringBuf name, TZtStringBuf value) {
xmlAttr* attr = xmlSetProp(NodePointer, XMLCHAR(name.c_str()), XMLCHAR(value.c_str()));
if (!attr) {
@@ -127,14 +127,14 @@ namespace NXml {
}
template <class T>
- typename std::enable_if<!std::is_convertible_v<T, TZtStringBuf>, void>::type
- TNode::SetAttr(TZtStringBuf name, const T& value) {
+ typename std::enable_if<!std::is_convertible_v<T, TZtStringBuf>, void>::type
+ TNode::SetAttr(TZtStringBuf name, const T& value) {
TStringStream ss;
ss << value;
- SetAttr(name, TZtStringBuf(ss.Str()));
+ SetAttr(name, TZtStringBuf(ss.Str()));
}
- inline void TNode::SetAttr(TZtStringBuf name) {
+ inline void TNode::SetAttr(TZtStringBuf name) {
xmlAttr* attr = xmlSetProp(NodePointer, XMLCHAR(name.c_str()), nullptr);
if (!attr) {
@@ -144,7 +144,7 @@ namespace NXml {
}
}
- inline void TNode::DelAttr(TZtStringBuf name) {
+ inline void TNode::DelAttr(TZtStringBuf name) {
if (xmlUnsetProp(NodePointer, XMLCHAR(name.c_str())) < 0)
THROW(XmlException, "Can't delete node attribute <"
<< name
@@ -152,14 +152,14 @@ namespace NXml {
}
template <class T>
- typename std::enable_if<!std::is_convertible_v<T, TZtStringBuf>, TNode>::type
- TNode::AddChild(TZtStringBuf name, const T& value) {
+ typename std::enable_if<!std::is_convertible_v<T, TZtStringBuf>, TNode>::type
+ TNode::AddChild(TZtStringBuf name, const T& value) {
TStringStream ss;
ss << value;
- return AddChild(name, TZtStringBuf(ss.Str()));
+ return AddChild(name, TZtStringBuf(ss.Str()));
}
- inline TNode TNode::AddChild(TZtStringBuf name, TZtStringBuf value) {
+ inline TNode TNode::AddChild(TZtStringBuf name, TZtStringBuf value) {
if (IsNull()) {
THROW(XmlException, "addChild [name=" << name << ", value=" << value
<< "]: can't add child to null node");
@@ -179,18 +179,18 @@ namespace NXml {
<< "]: xmlNewTextChild returned NULL");
}
- return TNode(DocPointer, child);
+ return TNode(DocPointer, child);
}
template <class T>
- typename std::enable_if<!std::is_convertible_v<T, TStringBuf>, TNode>::type
- TNode::AddText(const T& value) {
+ typename std::enable_if<!std::is_convertible_v<T, TStringBuf>, TNode>::type
+ TNode::AddText(const T& value) {
TStringStream ss;
ss << value;
return AddText(ss.Str());
}
- inline TNode TNode::AddText(TStringBuf value) {
+ inline TNode TNode::AddText(TStringBuf value) {
if (IsNull()) {
THROW(XmlException, "addChild [value=" << value
<< "]: can't add child to null node");
diff --git a/library/cpp/xml/document/xml-document-decl.h b/library/cpp/xml/document/xml-document-decl.h
index bfda1fb7e6..7b900939ab 100644
--- a/library/cpp/xml/document/xml-document-decl.h
+++ b/library/cpp/xml/document/xml-document-decl.h
@@ -1,19 +1,19 @@
#pragma once
-#include <library/cpp/string_utils/ztstrbuf/ztstrbuf.h>
-
+#include <library/cpp/string_utils/ztstrbuf/ztstrbuf.h>
+
#include <util/generic/string.h>
#include <util/generic/vector.h>
#include <util/stream/output.h>
#include <util/stream/str.h>
#include <algorithm>
-#include "libxml-guards.h"
+#include "libxml-guards.h"
namespace NXml {
- class TNode;
+ class TNode;
class TConstNodes;
- class TConstNode;
+ class TConstNode;
using TXPathContext = xmlXPathContext;
@@ -24,11 +24,11 @@ namespace NXml {
String,
RootName,
};
-
+
public:
/**
- * create TDocument
- * @param source: filename, XML string, or name for the root element (depends on @src)
+ * create TDocument
+ * @param source: filename, XML string, or name for the root element (depends on @src)
* @param src: source type: File | String | RootName
* throws if file not found or cannot be parsed
*/
@@ -44,10 +44,10 @@ namespace NXml {
/**
* get root element
*/
- TNode Root();
- TConstNode Root() const;
+ TNode Root();
+ TConstNode Root() const;
- void Save(IOutputStream& stream, TZtStringBuf enc = "", bool shouldFormat = true) const {
+ void Save(IOutputStream& stream, TZtStringBuf enc = "", bool shouldFormat = true) const {
int bufferSize = 0;
xmlChar* xmlBuff = nullptr;
const char* encoding = enc.size() ? enc.data() : Doc->encoding ? nullptr : "UTF-8";
@@ -56,14 +56,14 @@ namespace NXml {
stream.Write(xmlBuff, bufferSize);
}
- TString ToString(TZtStringBuf enc = "", bool shouldFormat = true) const {
+ TString ToString(TZtStringBuf enc = "", bool shouldFormat = true) const {
TStringStream s;
Save(s, enc, shouldFormat);
return s.Str();
}
void Swap(TDocument& that) {
- std::swap(this->Doc, that.Doc);
+ std::swap(this->Doc, that.Doc);
}
xmlDocPtr GetImpl() {
@@ -72,7 +72,7 @@ namespace NXml {
private:
void ParseFile(const TString& file);
- void ParseString(TZtStringBuf xml);
+ void ParseString(TZtStringBuf xml);
TDocument(TDocHolder doc)
: Doc(std::move(doc))
@@ -111,7 +111,7 @@ namespace NXml {
* get node by id
* @param number: node id
*/
- TConstNode operator[](size_t number) const;
+ TConstNode operator[](size_t number) const;
/**
* get number of nodes
@@ -123,50 +123,50 @@ namespace NXml {
return SizeValue;
}
- struct TNodeIter {
- const TConstNodes& Nodes;
- size_t Index;
+ struct TNodeIter {
+ const TConstNodes& Nodes;
+ size_t Index;
TConstNode operator*() const;
bool operator==(const TNodeIter& other) const {
- return Index == other.Index;
- }
+ return Index == other.Index;
+ }
bool operator!=(const TNodeIter& other) const {
- return !(*this == other);
- }
- TNodeIter operator++() {
- Index++;
- return *this;
- }
- };
+ return !(*this == other);
+ }
+ TNodeIter operator++() {
+ Index++;
+ return *this;
+ }
+ };
TNodeIter begin() const {
return TNodeIter{*this, 0};
}
TNodeIter end() const {
return TNodeIter{*this, size()};
}
-
+
private:
friend class TDocument;
- friend class TConstNode;
- friend class TNode;
+ friend class TConstNode;
+ friend class TNode;
TConstNodes(xmlDoc* doc, TXPathObjectPtr obj);
- size_t SizeValue;
- xmlDoc* Doc;
- TXPathObjectPtr Obj;
+ size_t SizeValue;
+ xmlDoc* Doc;
+ TXPathObjectPtr Obj;
};
class TNode {
public:
friend class TDocument;
- friend class TConstNode;
+ friend class TConstNode;
friend class TTextReader;
/**
* check if node is null
*/
- bool IsNull() const;
+ bool IsNull() const;
/**
* check if node is element node
@@ -186,15 +186,15 @@ namespace NXml {
TXPathContextPtr CreateXPathContext(const TNamespacesForXPath& nss = TNamespacesForXPath()) const;
/**
- * get all element nodes matching given xpath expression
+ * get all element nodes matching given xpath expression
* @param xpath: xpath expression
* @param quiet: don't throw exception if zero nodes found
* @param ns: explicitly specify XML namespaces to use and their prefixes
- *
- * For historical reasons, this only works for *element* nodes.
- * Use the XPath function if you need other kinds of nodes.
+ *
+ * For historical reasons, this only works for *element* nodes.
+ * Use the XPath function if you need other kinds of nodes.
*/
- TConstNodes Nodes(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const;
+ TConstNodes Nodes(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const;
/**
* get all element nodes matching given xpath expression
@@ -205,37 +205,37 @@ namespace NXml {
* For historical reasons, this only works for *element* nodes.
* Use the XPath function if you need other kinds of nodes.
*/
- TConstNodes Nodes(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const;
-
- /**
- * get all nodes matching given xpath expression
- * @param xpath: xpath expression
- * @param quiet: don't throw exception if zero nodes found
- * @param ns: explicitly specify XML namespaces to use and their prefixes
- */
- TConstNodes XPath(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const;
+ TConstNodes Nodes(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const;
/**
+ * get all nodes matching given xpath expression
+ * @param xpath: xpath expression
+ * @param quiet: don't throw exception if zero nodes found
+ * @param ns: explicitly specify XML namespaces to use and their prefixes
+ */
+ TConstNodes XPath(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const;
+
+ /**
* get all nodes matching given xpath expression
* @param xpath: xpath expression
* @param quiet: don't throw exception if zero nodes found
* @param ctxt: reusable xpath context
*/
- TConstNodes XPath(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const;
+ TConstNodes XPath(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const;
/**
- * get the first element node matching given xpath expression
+ * get the first element node matching given xpath expression
* @param xpath: path to node (from current node)
* @param quiet: don't throw exception if node not found,
* return null node (@see IsNull())
* @param ns: explicitly specify XML namespaces to use and their prefixes
- *
- * For historical reasons, this only works for *element* nodes.
- * Use the XPath function if you need other kinds of nodes.
+ *
+ * For historical reasons, this only works for *element* nodes.
+ * Use the XPath function if you need other kinds of nodes.
*/
/// @todo: quiet should be default, empty nodeset is not an error
- TNode Node(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath());
- TConstNode Node(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const;
+ TNode Node(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath());
+ TConstNode Node(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const;
/**
* get the first element node matching given xpath expression
@@ -247,8 +247,8 @@ namespace NXml {
* For historical reasons, this only works for *element* nodes.
* Use the XPath function if you need other kinds of nodes.
*/
- TNode Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt);
- TConstNode Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const;
+ TNode Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt);
+ TConstNode Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const;
/**
* get node first child
@@ -256,8 +256,8 @@ namespace NXml {
* @note if name is empty, returns the first child node of type "element"
* @note returns null node if no child found
*/
- TNode FirstChild(TZtStringBuf name);
- TConstNode FirstChild(TZtStringBuf name) const;
+ TNode FirstChild(TZtStringBuf name);
+ TConstNode FirstChild(TZtStringBuf name) const;
TNode FirstChild();
TConstNode FirstChild() const;
@@ -275,8 +275,8 @@ namespace NXml {
* @note if name is empty, returns the next sibling node of type "element"
* @node returns null node if no neighbour found
*/
- TNode NextSibling(TZtStringBuf name);
- TConstNode NextSibling(TZtStringBuf name) const;
+ TNode NextSibling(TZtStringBuf name);
+ TConstNode NextSibling(TZtStringBuf name) const;
TNode NextSibling();
TConstNode NextSibling() const;
@@ -286,7 +286,7 @@ namespace NXml {
* @param name: child name
* returns new empty node
*/
- TNode AddChild(TZtStringBuf name);
+ TNode AddChild(TZtStringBuf name);
/**
* create child node with given value
@@ -294,11 +294,11 @@ namespace NXml {
* @param value: node value
*/
template <class T>
- typename std::enable_if<!std::is_convertible_v<T, TZtStringBuf>, TNode>::type
- AddChild(TZtStringBuf name, const T& value);
-
- TNode AddChild(TZtStringBuf name, TZtStringBuf value);
+ typename std::enable_if<!std::is_convertible_v<T, TZtStringBuf>, TNode>::type
+ AddChild(TZtStringBuf name, const T& value);
+ TNode AddChild(TZtStringBuf name, TZtStringBuf value);
+
/**
* add child node, making recursive copy of original
* @param node: node to copy from
@@ -312,18 +312,18 @@ namespace NXml {
* @param value: node value
*/
template <class T>
- typename std::enable_if<!std::is_convertible_v<T, TStringBuf>, TNode>::type
- AddText(const T& value);
-
- TNode AddText(TStringBuf value);
+ typename std::enable_if<!std::is_convertible_v<T, TStringBuf>, TNode>::type
+ AddText(const T& value);
+ TNode AddText(TStringBuf value);
+
/**
* get node attribute
* @param name: attribute name
* throws exception if attribute not found
*/
template <class T>
- T Attr(TZtStringBuf name) const;
+ T Attr(TZtStringBuf name) const;
/**
* get node attribute
@@ -331,7 +331,7 @@ namespace NXml {
* returns default value if attribute not found
*/
template <class T>
- T Attr(TZtStringBuf name, const T& defvalue) const;
+ T Attr(TZtStringBuf name, const T& defvalue) const;
/**
* get node attribute
@@ -340,7 +340,7 @@ namespace NXml {
* throws exception if attribute not found
*/
template <class T>
- void Attr(TZtStringBuf name, T& value) const;
+ void Attr(TZtStringBuf name, T& value) const;
/**
* get node attribute
@@ -350,14 +350,14 @@ namespace NXml {
* returns default value if attribute not found, attr value otherwise
*/
template <class T>
- void Attr(TZtStringBuf name, T& value, const T& defvalue) const;
+ void Attr(TZtStringBuf name, T& value, const T& defvalue) const;
/**
* get node value (text)
* @throws exception if node is blank
*/
template <class T>
- T Value() const;
+ T Value() const;
/**
* get node value
@@ -365,37 +365,37 @@ namespace NXml {
* returns default value if node is blank
*/
template <class T>
- T Value(const T& defvalue) const;
+ T Value(const T& defvalue) const;
/**
* set node value
* @param value: new text value
*/
template <class T>
- typename std::enable_if<!std::is_convertible_v<T, TStringBuf>, void>::type
- SetValue(const T& value);
-
- void SetValue(TStringBuf value);
+ typename std::enable_if<!std::is_convertible_v<T, TStringBuf>, void>::type
+ SetValue(const T& value);
+ void SetValue(TStringBuf value);
+
/**
* set/reset node attribute value,
* if attribute does not exist, it'll be created
* @param name: attribute name
* @param value: attribute value
*/
- template<class T>
- typename std::enable_if<!std::is_convertible_v<T, TZtStringBuf>, void>::type
- SetAttr(TZtStringBuf name, const T& value);
-
- void SetAttr(TZtStringBuf name, TZtStringBuf value);
+ template<class T>
+ typename std::enable_if<!std::is_convertible_v<T, TZtStringBuf>, void>::type
+ SetAttr(TZtStringBuf name, const T& value);
- void SetAttr(TZtStringBuf name);
+ void SetAttr(TZtStringBuf name, TZtStringBuf value);
+ void SetAttr(TZtStringBuf name);
+
/**
* delete node attribute
* @param name: attribute name
*/
- void DelAttr(TZtStringBuf name);
+ void DelAttr(TZtStringBuf name);
/**
* set node application data
@@ -421,13 +421,13 @@ namespace NXml {
/**
* get node xml representation
*/
- TString ToString(TZtStringBuf enc = "") const {
+ TString ToString(TZtStringBuf enc = "") const {
TStringStream s;
Save(s, enc);
return s.Str();
}
- void Save(IOutputStream& stream, TZtStringBuf enc = "", bool shouldFormat = false) const;
- void SaveAsHtml(IOutputStream& stream, TZtStringBuf enc = "", bool shouldFormat = false) const;
+ void Save(IOutputStream& stream, TZtStringBuf enc = "", bool shouldFormat = false) const;
+ void SaveAsHtml(IOutputStream& stream, TZtStringBuf enc = "", bool shouldFormat = false) const;
/**
* get pointer to internal node
@@ -448,7 +448,7 @@ namespace NXml {
/**
* constructs null node
*/
- TNode()
+ TNode()
: NodePointer(nullptr)
, DocPointer(nullptr)
{
@@ -457,33 +457,33 @@ namespace NXml {
private:
friend class TConstNodes;
- TNode(xmlDoc* doc, xmlNode* node)
- : NodePointer(node)
- , DocPointer(doc)
+ TNode(xmlDoc* doc, xmlNode* node)
+ : NodePointer(node)
+ , DocPointer(doc)
{
}
- TNode Find(xmlNode* start, TZtStringBuf name);
+ TNode Find(xmlNode* start, TZtStringBuf name);
template <class T>
- void AttrInternal(TCharPtr& value, T& res, TStringBuf errContext) const;
+ void AttrInternal(TCharPtr& value, T& res, TStringBuf errContext) const;
- void SaveInternal(IOutputStream& stream, TZtStringBuf enc, int options) const;
+ void SaveInternal(IOutputStream& stream, TZtStringBuf enc, int options) const;
- xmlNode* NodePointer;
- xmlDoc* DocPointer;
+ xmlNode* NodePointer;
+ xmlDoc* DocPointer;
};
class TConstNode {
public:
friend class TDocument;
friend class TConstNodes;
- friend class TNode;
+ friend class TNode;
/**
* check if node is null
*/
bool IsNull() const {
- return ActualNode.IsNull();
+ return ActualNode.IsNull();
}
bool IsElementNode() const {
@@ -491,9 +491,9 @@ namespace NXml {
}
TConstNode Parent() const {
- return ActualNode.Parent();
- }
-
+ return ActualNode.Parent();
+ }
+
/**
* Create xpath context to be used later for fast xpath evaluation.
* @param nss: explicitly specify XML namespaces to use and their prefixes
@@ -503,16 +503,16 @@ namespace NXml {
}
/**
- * get all element nodes matching given xpath expression
+ * get all element nodes matching given xpath expression
* @param xpath: xpath expression
* @param quiet: don't throw exception if zero nodes found
* @param ns: explicitly specify XML namespaces to use and their prefixes
- *
- * For historical reasons, this only works for *element* nodes.
- * Use the XPath function if you need other kinds of nodes.
+ *
+ * For historical reasons, this only works for *element* nodes.
+ * Use the XPath function if you need other kinds of nodes.
*/
- TConstNodes Nodes(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const {
- return ActualNode.Nodes(xpath, quiet, ns);
+ TConstNodes Nodes(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const {
+ return ActualNode.Nodes(xpath, quiet, ns);
}
/**
@@ -524,42 +524,42 @@ namespace NXml {
* For historical reasons, this only works for *element* nodes.
* Use the XPath function if you need other kinds of nodes.
*/
- TConstNodes Nodes(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
+ TConstNodes Nodes(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
return ActualNode.Nodes(xpath, quiet, ctxt);
}
/**
- * get all nodes matching given xpath expression
- * @param xpath: xpath expression
- * @param quiet: don't throw exception if zero nodes found
+ * get all nodes matching given xpath expression
+ * @param xpath: xpath expression
+ * @param quiet: don't throw exception if zero nodes found
* @param ns: explicitly specify XML namespaces to use and their prefixes
- */
- TConstNodes XPath(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const {
- return ActualNode.XPath(xpath, quiet, ns);
- }
-
- /**
+ */
+ TConstNodes XPath(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const {
+ return ActualNode.XPath(xpath, quiet, ns);
+ }
+
+ /**
* get all nodes matching given xpath expression
* @param xpath: xpath expression
* @param quiet: don't throw exception if zero nodes found
* @param ctxt: reusable xpath context
*/
- TConstNodes XPath(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
+ TConstNodes XPath(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
return ActualNode.XPath(xpath, quiet, ctxt);
}
/**
- * get the first element node matching given xpath expression
+ * get the first element node matching given xpath expression
* @param xpath: path to node (from current node)
* @param quiet: don't throw exception if node not found,
* return null node (@see IsNull())
* @param ns: explicitly specify XML namespaces to use and their prefixes
- *
- * For historical reasons, this only works for *element* nodes.
- * Use the XPath function if you need other kinds of nodes.
+ *
+ * For historical reasons, this only works for *element* nodes.
+ * Use the XPath function if you need other kinds of nodes.
*/
- TConstNode Node(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const {
- return ActualNode.Node(xpath, quiet, ns);
+ TConstNode Node(TZtStringBuf xpath, bool quiet = false, const TNamespacesForXPath& ns = TNamespacesForXPath()) const {
+ return ActualNode.Node(xpath, quiet, ns);
}
/**
@@ -572,12 +572,12 @@ namespace NXml {
* For historical reasons, this only works for *element* nodes.
* Use the XPath function if you need other kinds of nodes.
*/
- TConstNode Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
+ TConstNode Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
return ActualNode.Node(xpath, quiet, ctxt);
}
- TConstNode FirstChild(TZtStringBuf name) const {
- return ActualNode.FirstChild(name);
+ TConstNode FirstChild(TZtStringBuf name) const {
+ return ActualNode.FirstChild(name);
}
TConstNode FirstChild() const {
@@ -589,8 +589,8 @@ namespace NXml {
* @param name: neighbour name
* throws exception if no neighbour found
*/
- TConstNode NextSibling(TZtStringBuf name) const {
- return ActualNode.NextSibling(name);
+ TConstNode NextSibling(TZtStringBuf name) const {
+ return ActualNode.NextSibling(name);
}
TConstNode NextSibling() const {
@@ -603,8 +603,8 @@ namespace NXml {
* throws exception if attribute not found
*/
template <class T>
- T Attr(TZtStringBuf name) const {
- return ActualNode.Attr<T>(name);
+ T Attr(TZtStringBuf name) const {
+ return ActualNode.Attr<T>(name);
}
/**
@@ -613,8 +613,8 @@ namespace NXml {
* returns default value if attribute not found
*/
template <class T>
- T Attr(TZtStringBuf name, const T& defvalue) const {
- return ActualNode.Attr(name, defvalue);
+ T Attr(TZtStringBuf name, const T& defvalue) const {
+ return ActualNode.Attr(name, defvalue);
}
/**
@@ -624,8 +624,8 @@ namespace NXml {
* throws exception if attribute not found
*/
template <class T>
- void Attr(TZtStringBuf name, T& value) const {
- return ActualNode.Attr(name, value);
+ void Attr(TZtStringBuf name, T& value) const {
+ return ActualNode.Attr(name, value);
}
/**
@@ -636,8 +636,8 @@ namespace NXml {
* returns default value if attribute not found, attr value otherwise
*/
template <class T>
- void Attr(TZtStringBuf name, T& value, const T& defvalue) const {
- return ActualNode.Attr(name, value, defvalue);
+ void Attr(TZtStringBuf name, T& value, const T& defvalue) const {
+ return ActualNode.Attr(name, value, defvalue);
}
/**
@@ -646,7 +646,7 @@ namespace NXml {
*/
template <class T>
T Value() const {
- return ActualNode.Value<T>();
+ return ActualNode.Value<T>();
}
/**
@@ -656,7 +656,7 @@ namespace NXml {
*/
template <class T>
T Value(const T& defvalue) const {
- return ActualNode.Value(defvalue);
+ return ActualNode.Value(defvalue);
}
/**
@@ -691,28 +691,28 @@ namespace NXml {
* get node xpath
*/
TString Path() const {
- return ActualNode.Path();
+ return ActualNode.Path();
}
/**
* get node xml representation
*/
- TString ToString(TZtStringBuf enc = "") const {
+ TString ToString(TZtStringBuf enc = "") const {
return ActualNode.ToString(enc);
}
TConstNode() = default;
- TConstNode(TNode node)
- : ActualNode(node)
+ TConstNode(TNode node)
+ : ActualNode(node)
{
}
TNode ConstCast() const {
- return ActualNode;
- }
-
+ return ActualNode;
+ }
+
private:
- TNode ActualNode;
+ TNode ActualNode;
};
}
diff --git a/library/cpp/xml/document/xml-document.cpp b/library/cpp/xml/document/xml-document.cpp
index 18a554d732..23c16cf495 100644
--- a/library/cpp/xml/document/xml-document.cpp
+++ b/library/cpp/xml/document/xml-document.cpp
@@ -75,7 +75,7 @@ namespace NXml {
Doc = std::move(doc);
}
- void TDocument::ParseString(TZtStringBuf xml) {
+ void TDocument::ParseString(TZtStringBuf xml) {
TParserCtxtPtr pctx(xmlNewParserCtxt());
if (pctx.Get() == nullptr)
THROW(XmlException, "Can't create parser context");
@@ -89,19 +89,19 @@ namespace NXml {
}
TNode TDocument::Root() {
- xmlNode* r = xmlDocGetRootElement(Doc.Get());
+ xmlNode* r = xmlDocGetRootElement(Doc.Get());
if (r == nullptr)
THROW(XmlException, "TDocument hasn't root element");
- return TNode(Doc.Get(), r);
+ return TNode(Doc.Get(), r);
}
TConstNode TDocument::Root() const {
- xmlNode* r = xmlDocGetRootElement(Doc.Get());
+ xmlNode* r = xmlDocGetRootElement(Doc.Get());
if (r == nullptr)
THROW(XmlException, "TDocument hasn't root element");
- return TConstNode(TNode(Doc.Get(), r));
+ return TConstNode(TNode(Doc.Get(), r));
}
bool TNode::IsNull() const {
@@ -126,12 +126,12 @@ namespace NXml {
return ctx;
}
- TConstNodes TNode::XPath(TZtStringBuf xpath, bool quiet, const TNamespacesForXPath& ns) const {
+ TConstNodes TNode::XPath(TZtStringBuf xpath, bool quiet, const TNamespacesForXPath& ns) const {
TXPathContextPtr ctxt = CreateXPathContext(ns);
return XPath(xpath, quiet, *ctxt);
}
- TConstNodes TNode::XPath(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
+ TConstNodes TNode::XPath(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
if (xmlXPathSetContextNode(NodePointer, &ctxt) != 0)
THROW(XmlException, "Can't set xpath context node, probably the context is associated with another document");
@@ -141,59 +141,59 @@ namespace NXml {
TConstNodes nodes(DocPointer, obj);
- if (nodes.Size() == 0 && !quiet)
+ if (nodes.Size() == 0 && !quiet)
THROW(NodeNotFound, xpath);
return nodes;
}
- TConstNodes TNode::Nodes(TZtStringBuf xpath, bool quiet, const TNamespacesForXPath& ns) const {
+ TConstNodes TNode::Nodes(TZtStringBuf xpath, bool quiet, const TNamespacesForXPath& ns) const {
TXPathContextPtr ctxt = CreateXPathContext(ns);
return Nodes(xpath, quiet, *ctxt);
}
- TConstNodes TNode::Nodes(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
+ TConstNodes TNode::Nodes(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
TConstNodes nodes = XPath(xpath, quiet, ctxt);
- if (nodes.Size() != 0 && !nodes[0].IsElementNode())
- THROW(XmlException, "xpath points to non-element nodes: " << xpath);
- return nodes;
- }
+ if (nodes.Size() != 0 && !nodes[0].IsElementNode())
+ THROW(XmlException, "xpath points to non-element nodes: " << xpath);
+ return nodes;
+ }
- TNode TNode::Node(TZtStringBuf xpath, bool quiet, const TNamespacesForXPath& ns) {
+ TNode TNode::Node(TZtStringBuf xpath, bool quiet, const TNamespacesForXPath& ns) {
TXPathContextPtr ctxt = CreateXPathContext(ns);
return Node(xpath, quiet, *ctxt);
}
- TConstNode TNode::Node(TZtStringBuf xpath, bool quiet, const TNamespacesForXPath& ns) const {
+ TConstNode TNode::Node(TZtStringBuf xpath, bool quiet, const TNamespacesForXPath& ns) const {
TXPathContextPtr ctxt = CreateXPathContext(ns);
return Node(xpath, quiet, *ctxt);
}
- TNode TNode::Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) {
+ TNode TNode::Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) {
TConstNodes n = Nodes(xpath, quiet, ctxt);
- if (n.Size() == 0 && !quiet)
+ if (n.Size() == 0 && !quiet)
THROW(NodeNotFound, xpath);
- if (n.Size() == 0)
- return TNode();
+ if (n.Size() == 0)
+ return TNode();
else
return n[0].ConstCast();
}
- TConstNode TNode::Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
+ TConstNode TNode::Node(TZtStringBuf xpath, bool quiet, TXPathContext& ctxt) const {
return const_cast<TNode*>(this)->Node(xpath, quiet, ctxt);
}
- TNode TNode::FirstChild(TZtStringBuf name) {
- if (IsNull())
+ TNode TNode::FirstChild(TZtStringBuf name) {
+ if (IsNull())
THROW(XmlException, "Node is null");
- return Find(NodePointer->children, name);
+ return Find(NodePointer->children, name);
}
- TConstNode TNode::FirstChild(TZtStringBuf name) const {
- return const_cast<TNode*>(this)->FirstChild(name);
+ TConstNode TNode::FirstChild(TZtStringBuf name) const {
+ return const_cast<TNode*>(this)->FirstChild(name);
}
TNode TNode::FirstChild() {
@@ -218,15 +218,15 @@ namespace NXml {
return const_cast<TNode*>(this)->Parent();
}
- TNode TNode::NextSibling(TZtStringBuf name) {
- if (IsNull())
+ TNode TNode::NextSibling(TZtStringBuf name) {
+ if (IsNull())
THROW(XmlException, "Node is null");
- return Find(NodePointer->next, name);
+ return Find(NodePointer->next, name);
}
- TConstNode TNode::NextSibling(TZtStringBuf name) const {
- return const_cast<TNode*>(this)->NextSibling(name);
+ TConstNode TNode::NextSibling(TZtStringBuf name) const {
+ return const_cast<TNode*>(this)->NextSibling(name);
}
TNode TNode::NextSibling() {
@@ -242,7 +242,7 @@ namespace NXml {
/* NOTE: by default child will inherit it's parent ns */
- TNode TNode::AddChild(TZtStringBuf name) {
+ TNode TNode::AddChild(TZtStringBuf name) {
return AddChild(name, "");
}
@@ -262,12 +262,12 @@ namespace NXml {
return NodePointer->_private;
}
- TNode TNode::Find(xmlNode* start, TZtStringBuf name) {
+ TNode TNode::Find(xmlNode* start, TZtStringBuf name) {
for (; start; start = start->next)
if (start->type == XML_ELEMENT_NODE && (name.empty() || !xmlStrcmp(start->name, XMLCHAR(name.c_str()))))
- return TNode(DocPointer, start);
+ return TNode(DocPointer, start);
- return TNode();
+ return TNode();
}
TString TNode::Name() const {
@@ -278,7 +278,7 @@ namespace NXml {
}
TString TNode::Path() const {
- TCharPtr path(xmlGetNodePath(NodePointer));
+ TCharPtr path(xmlGetNodePath(NodePointer));
if (!!path)
return CAST2CHAR(path.Get());
else
@@ -313,7 +313,7 @@ namespace NXml {
return len;
}
- void TNode::SaveInternal(IOutputStream& stream, TZtStringBuf enc, int options) const {
+ void TNode::SaveInternal(IOutputStream& stream, TZtStringBuf enc, int options) const {
const char* encoding = enc.size() ? enc.data() : "utf-8";
TSaveCtxtPtr ctx(xmlSaveToIO(XmlWriteToOstream, /* close */ nullptr, &stream,
encoding, options));
@@ -321,45 +321,45 @@ namespace NXml {
THROW(XmlException, "Failed saving node to stream");
}
- void TNode::Save(IOutputStream& stream, TZtStringBuf enc, bool shouldFormat) const {
+ void TNode::Save(IOutputStream& stream, TZtStringBuf enc, bool shouldFormat) const {
SaveInternal(stream, enc, shouldFormat ? XML_SAVE_FORMAT : 0);
}
- void TNode::SaveAsHtml(IOutputStream& stream, TZtStringBuf enc, bool shouldFormat) const {
+ void TNode::SaveAsHtml(IOutputStream& stream, TZtStringBuf enc, bool shouldFormat) const {
int options = XML_SAVE_AS_HTML;
options |= shouldFormat ? XML_SAVE_FORMAT : 0;
SaveInternal(stream, enc, options);
}
TConstNodes::TConstNodes(const TConstNodes& nodes)
- : SizeValue(nodes.Size())
- , Doc(nodes.Doc)
- , Obj(nodes.Obj)
+ : SizeValue(nodes.Size())
+ , Doc(nodes.Doc)
+ , Obj(nodes.Obj)
{
}
TConstNodes& TConstNodes::operator=(const TConstNodes& nodes) {
if (this != &nodes) {
- SizeValue = nodes.Size();
- Doc = nodes.Doc;
- Obj = nodes.Obj;
+ SizeValue = nodes.Size();
+ Doc = nodes.Doc;
+ Obj = nodes.Obj;
}
return *this;
}
TConstNodes::TConstNodes(TConstNodesRef ref)
- : SizeValue(ref.r_.Size())
- , Doc(ref.r_.Doc)
- , Obj(ref.r_.Obj)
+ : SizeValue(ref.r_.Size())
+ , Doc(ref.r_.Doc)
+ , Obj(ref.r_.Obj)
{
}
TConstNodes& TConstNodes::operator=(TConstNodesRef ref) {
if (this != &ref.r_) {
- SizeValue = ref.r_.Size();
- Doc = ref.r_.Doc;
- Obj = ref.r_.Obj;
+ SizeValue = ref.r_.Size();
+ Doc = ref.r_.Doc;
+ Obj = ref.r_.Obj;
}
return *this;
}
@@ -376,18 +376,18 @@ namespace NXml {
}
TConstNode TConstNodes::operator[](size_t number) const {
- if (number + 1 > Size())
+ if (number + 1 > Size())
THROW(XmlException, "index out of range " << number);
- if (!Obj || !Obj->nodesetval)
- THROW(XmlException, "Broken TConstNodes object, Obj is null");
+ if (!Obj || !Obj->nodesetval)
+ THROW(XmlException, "Broken TConstNodes object, Obj is null");
- xmlNode* node = Obj->nodesetval->nodeTab[number];
- return TNode(Doc, node);
+ xmlNode* node = Obj->nodesetval->nodeTab[number];
+ return TNode(Doc, node);
}
TConstNode TConstNodes::TNodeIter::operator*() const {
- return Nodes[Index];
- }
-
+ return Nodes[Index];
+ }
+
}
diff --git a/library/cpp/xml/document/xml-document.h b/library/cpp/xml/document/xml-document.h
index 829ba09cc4..728f76761f 100644
--- a/library/cpp/xml/document/xml-document.h
+++ b/library/cpp/xml/document/xml-document.h
@@ -1,4 +1,4 @@
#pragma once
-#include "xml-document-decl.h"
-#include "node-attr.h"
+#include "xml-document-decl.h"
+#include "node-attr.h"
diff --git a/library/cpp/xml/document/xml-document_ut.cpp b/library/cpp/xml/document/xml-document_ut.cpp
index 9f537b75c4..a8cfb45117 100644
--- a/library/cpp/xml/document/xml-document_ut.cpp
+++ b/library/cpp/xml/document/xml-document_ut.cpp
@@ -1,8 +1,8 @@
#include <library/cpp/testing/unittest/registar.h>
#include <util/generic/map.h>
-
-#include "xml-document.h"
-
+
+#include "xml-document.h"
+
Y_UNIT_TEST_SUITE(TestXmlDocument) {
Y_UNIT_TEST(Iteration) {
NXml::TDocument xml(
@@ -19,40 +19,40 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {
}
Y_UNIT_TEST(ParseString) {
- NXml::TDocument xml(
+ NXml::TDocument xml(
"<?xml version=\"1.0\"?>\n"
"<root>\n"
"<a><b len=\"15\" correct=\"1\">hello world</b></a>\n"
"<text>Некоторый текст</text>\n"
"</root>",
NXml::TDocument::String);
-
- NXml::TConstNode root = xml.Root();
- NXml::TConstNode b = root.Node("a/b");
- UNIT_ASSERT_EQUAL(b.Attr<int>("len"), 15);
- UNIT_ASSERT_EQUAL(b.Attr<bool>("correct"), true);
-
- NXml::TConstNode text = root.Node("text");
+
+ NXml::TConstNode root = xml.Root();
+ NXml::TConstNode b = root.Node("a/b");
+ UNIT_ASSERT_EQUAL(b.Attr<int>("len"), 15);
+ UNIT_ASSERT_EQUAL(b.Attr<bool>("correct"), true);
+
+ NXml::TConstNode text = root.Node("text");
UNIT_ASSERT_EQUAL(text.Value<TString>(), "Некоторый текст");
- }
+ }
Y_UNIT_TEST(SerializeString) {
- NXml::TDocument xml("frob", NXml::TDocument::RootName);
- xml.Root().SetAttr("xyzzy", "Frobozz");
- xml.Root().SetAttr("kulness", 0.3);
- xml.Root().SetAttr("timelimit", 3);
-
- NXml::TNode authors = xml.Root().AddChild("authors");
- authors.AddChild("graham").SetAttr("name", "Nelson");
- authors.AddChild("zarf").SetValue("Andrew Plotkin");
- authors.AddChild("emshort", "Emily Short");
-
+ NXml::TDocument xml("frob", NXml::TDocument::RootName);
+ xml.Root().SetAttr("xyzzy", "Frobozz");
+ xml.Root().SetAttr("kulness", 0.3);
+ xml.Root().SetAttr("timelimit", 3);
+
+ NXml::TNode authors = xml.Root().AddChild("authors");
+ authors.AddChild("graham").SetAttr("name", "Nelson");
+ authors.AddChild("zarf").SetValue("Andrew Plotkin");
+ authors.AddChild("emshort", "Emily Short");
+
TString data = xml.ToString("utf-8");
- UNIT_ASSERT_EQUAL(data, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
- "<frob xyzzy=\"Frobozz\" kulness=\"0.3\" timelimit=\"3\">\n"
+ UNIT_ASSERT_EQUAL(data, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<frob xyzzy=\"Frobozz\" kulness=\"0.3\" timelimit=\"3\">\n"
" <authors>\n"
" <graham name=\"Nelson\"/>\n"
" <zarf>Andrew Plotkin</zarf>\n"
- " <emshort>Emily Short</emshort>\n"
+ " <emshort>Emily Short</emshort>\n"
" </authors>\n"
"</frob>\n");
// check default utf8 output with ru
@@ -62,7 +62,7 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {
UNIT_ASSERT_VALUES_EQUAL(xml2.ToString(), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<frob xyzzy=\"привет =)\"/>\n");
}
- }
+ }
Y_UNIT_TEST(XPathNs) {
using namespace NXml;
TDocument xml(
@@ -114,11 +114,11 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {
UNIT_ASSERT_EQUAL(node.Value<TString>(), "");
node = node.NextSibling();
UNIT_ASSERT_EQUAL(node.IsNull(), true);
- TStringStream iterLog;
+ TStringStream iterLog;
for (const auto& node2 : root.Nodes("/root/*")) {
iterLog << node2.Name() << ';';
- }
- UNIT_ASSERT_STRINGS_EQUAL(iterLog.Str(), "a;c;");
+ }
+ UNIT_ASSERT_STRINGS_EQUAL(iterLog.Str(), "a;c;");
// get only element nodes, ignore text nodes with empty "name" param
node = root.FirstChild(TString());
@@ -152,29 +152,29 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {
UNIT_ASSERT_EXCEPTION(node.IsText(), yexception);
}
Y_UNIT_TEST(DefVal) {
- using namespace NXml;
- TDocument xml("<?xml version=\"1.0\"?>\n"
+ using namespace NXml;
+ TDocument xml("<?xml version=\"1.0\"?>\n"
"<root><a></a></root>",
NXml::TDocument::String);
- UNIT_ASSERT_EQUAL(xml.Root().Node("a", true).Node("b", true).Value<int>(3), 3);
- }
+ UNIT_ASSERT_EQUAL(xml.Root().Node("a", true).Node("b", true).Value<int>(3), 3);
+ }
Y_UNIT_TEST(NodesVsXPath) {
- using namespace NXml;
- TDocument xml("<?xml version=\"1.0\"?>\n"
+ using namespace NXml;
+ TDocument xml("<?xml version=\"1.0\"?>\n"
"<root><a x=\"y\"></a></root>",
NXml::TDocument::String);
- UNIT_ASSERT_EXCEPTION(xml.Root().Nodes("/root/a/@x"), yexception);
- UNIT_ASSERT_VALUES_EQUAL(xml.Root().XPath("/root/a/@x").Size(), 1);
- }
+ UNIT_ASSERT_EXCEPTION(xml.Root().Nodes("/root/a/@x"), yexception);
+ UNIT_ASSERT_VALUES_EQUAL(xml.Root().XPath("/root/a/@x").Size(), 1);
+ }
Y_UNIT_TEST(NodeIsFirst) {
- using namespace NXml;
- TDocument xml("<?xml version=\"1.0\"?>\n"
- "<root><a x=\"y\">first</a>"
+ using namespace NXml;
+ TDocument xml("<?xml version=\"1.0\"?>\n"
+ "<root><a x=\"y\">first</a>"
"<a>second</a></root>",
NXml::TDocument::String);
- UNIT_ASSERT_EXCEPTION(xml.Root().Node("/root/a/@x"), yexception);
+ UNIT_ASSERT_EXCEPTION(xml.Root().Node("/root/a/@x"), yexception);
UNIT_ASSERT_STRINGS_EQUAL(xml.Root().Node("/root/a").Value<TString>(), "first");
- }
+ }
Y_UNIT_TEST(CopyNode) {
using namespace NXml;
// default-construct empty node
@@ -304,16 +304,16 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {
UNIT_ASSERT_EXCEPTION(xml1.Root(), yexception);
UNIT_ASSERT_VALUES_EQUAL(xml2.Root().ToString(), "<foo><bar/></foo>");
}
-
- Y_UNIT_TEST(StringConversion) {
- using namespace NXml;
- TDocument xml("foo", TDocument::RootName);
- auto root = xml.Root();
- const TStringBuf stringBuf = "bar";
- root.SetAttr("bar", stringBuf);
- const TString tString = "baz";
- root.SetAttr("baz", tString);
- root.SetAttr("quux", "literal");
- root.SetAttr("frob", 500);
- }
-}
+
+ Y_UNIT_TEST(StringConversion) {
+ using namespace NXml;
+ TDocument xml("foo", TDocument::RootName);
+ auto root = xml.Root();
+ const TStringBuf stringBuf = "bar";
+ root.SetAttr("bar", stringBuf);
+ const TString tString = "baz";
+ root.SetAttr("baz", tString);
+ root.SetAttr("quux", "literal");
+ root.SetAttr("frob", 500);
+ }
+}
diff --git a/library/cpp/xml/document/xml-textreader.cpp b/library/cpp/xml/document/xml-textreader.cpp
index b946f1fbf2..ab5c0436f3 100644
--- a/library/cpp/xml/document/xml-textreader.cpp
+++ b/library/cpp/xml/document/xml-textreader.cpp
@@ -113,15 +113,15 @@ namespace NXml {
return TempStringResult(xmlTextReaderGetAttributeNo(Impl.Get(), number));
}
- TString TTextReader::GetAttribute(TZtStringBuf name) const {
+ TString TTextReader::GetAttribute(TZtStringBuf name) const {
return TempStringResult(xmlTextReaderGetAttribute(Impl.Get(), XMLCHAR(name.data())));
}
- TString TTextReader::GetAttribute(TZtStringBuf localName, TZtStringBuf nsUri) const {
+ TString TTextReader::GetAttribute(TZtStringBuf localName, TZtStringBuf nsUri) const {
return TempStringResult(xmlTextReaderGetAttributeNs(Impl.Get(), XMLCHAR(localName.data()), XMLCHAR(nsUri.data())));
}
- TString TTextReader::LookupNamespace(TZtStringBuf prefix) const {
+ TString TTextReader::LookupNamespace(TZtStringBuf prefix) const {
return TempStringResult(xmlTextReaderLookupNamespace(Impl.Get(), XMLCHAR(prefix.data())));
}
@@ -129,11 +129,11 @@ namespace NXml {
return BoolResult(xmlTextReaderMoveToAttributeNo(Impl.Get(), number));
}
- bool TTextReader::MoveToAttribute(TZtStringBuf name) {
+ bool TTextReader::MoveToAttribute(TZtStringBuf name) {
return BoolResult(xmlTextReaderMoveToAttribute(Impl.Get(), XMLCHAR(name.data())));
}
- bool TTextReader::MoveToAttribute(TZtStringBuf localName, TZtStringBuf nsUri) {
+ bool TTextReader::MoveToAttribute(TZtStringBuf localName, TZtStringBuf nsUri) {
return BoolResult(xmlTextReaderMoveToAttributeNs(Impl.Get(), XMLCHAR(localName.data()), XMLCHAR(nsUri.data())));
}
diff --git a/library/cpp/xml/document/xml-textreader.h b/library/cpp/xml/document/xml-textreader.h
index ab4c329d26..1507bfe22c 100644
--- a/library/cpp/xml/document/xml-textreader.h
+++ b/library/cpp/xml/document/xml-textreader.h
@@ -5,8 +5,8 @@
#include <contrib/libs/libxml/include/libxml/xmlreader.h>
-#include <library/cpp/string_utils/ztstrbuf/ztstrbuf.h>
-
+#include <library/cpp/string_utils/ztstrbuf/ztstrbuf.h>
+
#include <util/generic/noncopyable.h>
#include <util/generic/ptr.h>
#include <util/generic/strbuf.h>
@@ -222,21 +222,21 @@ namespace NXml {
* Provides the value of the attribute with the specified qualified name.
* @param name the qualified name of the attribute
*/
- TString GetAttribute(TZtStringBuf name) const;
+ TString GetAttribute(TZtStringBuf name) const;
/**
* Provides the value of the specified attribute.
* @param localName the local name of the attribute
* @param nsUri the namespace URI of the attribute
*/
- TString GetAttribute(TZtStringBuf localName, TZtStringBuf nsUri) const;
+ TString GetAttribute(TZtStringBuf localName, TZtStringBuf nsUri) const;
/**
* Resolves a namespace prefix in the scope of the current element.
* @param prefix the prefix whose namespace URI is to be resolved. To return the default namespace, specify empty string.
* @return a string containing the namespace URI to which the prefix maps.
*/
- TString LookupNamespace(TZtStringBuf prefix) const;
+ TString LookupNamespace(TZtStringBuf prefix) const;
/**
* Moves the position of the current instance to the attribute with the specified index relative to the containing element.
@@ -250,7 +250,7 @@ namespace NXml {
* @param name the qualified name of the attribute
* @return true in case of success, false if not found
*/
- bool MoveToAttribute(TZtStringBuf name);
+ bool MoveToAttribute(TZtStringBuf name);
/**
* Moves the position of the current instance to the attribute with the specified local name and namespace URI.
@@ -258,7 +258,7 @@ namespace NXml {
* @param nsUri the namespace URI of the attribute
* @return true in case of success, false if not found
*/
- bool MoveToAttribute(TZtStringBuf localName, TZtStringBuf nsUri);
+ bool MoveToAttribute(TZtStringBuf localName, TZtStringBuf nsUri);
/**
* Moves the position of the current instance to the first attribute associated with the current node.
diff --git a/library/cpp/xml/document/ya.make b/library/cpp/xml/document/ya.make
index 86bbd639cf..c66f368d28 100644
--- a/library/cpp/xml/document/ya.make
+++ b/library/cpp/xml/document/ya.make
@@ -11,7 +11,7 @@ SRCS(
PEERDIR(
library/cpp/xml/init
contrib/libs/libxml
- library/cpp/string_utils/ztstrbuf
+ library/cpp/string_utils/ztstrbuf
)
END()
diff --git a/library/cpp/xml/init/ptr.h b/library/cpp/xml/init/ptr.h
index 7387c7cc40..bbc7ed9404 100644
--- a/library/cpp/xml/init/ptr.h
+++ b/library/cpp/xml/init/ptr.h
@@ -6,7 +6,7 @@
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <libxml/xmlsave.h>
-#include <libxml/uri.h>
+#include <libxml/uri.h>
#include <libxml/xmlschemas.h>
template <class T, void (*DestroyFun)(T*)>
diff --git a/library/python/ya.make b/library/python/ya.make
index 2e1eb6e0e1..c7870aae5b 100644
--- a/library/python/ya.make
+++ b/library/python/ya.make
@@ -203,7 +203,7 @@ RECURSE(
vault_client
watch_dog
watch_dog/example
- wiki
+ wiki
windows
windows/ut
yandex_tracker_client