diff options
author | alejes <alejes@yandex-team.ru> | 2022-02-10 16:49:20 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:20 +0300 |
commit | b60afd91b05e759239ecb08faaf494d5c7445d4e (patch) | |
tree | a8c3391fc9e065ab7e9ade6768708b244dff85d7 | |
parent | 523d26598d9784601932189f7fceb34d61bf7641 (diff) | |
download | ydb-b60afd91b05e759239ecb08faaf494d5c7445d4e.tar.gz |
Restoring authorship annotation for <alejes@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/string_utils/quote/quote.cpp | 10 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote.h | 2 | ||||
-rw-r--r-- | library/cpp/string_utils/quote/quote_ut.cpp | 32 | ||||
-rw-r--r-- | library/cpp/yson/node/node.cpp | 138 | ||||
-rw-r--r-- | library/cpp/yson/node/node.h | 20 | ||||
-rw-r--r-- | library/cpp/yson/node/node_ut.cpp | 128 |
6 files changed, 165 insertions, 165 deletions
diff --git a/library/cpp/string_utils/quote/quote.cpp b/library/cpp/string_utils/quote/quote.cpp index e523350b80..27cb3a76d0 100644 --- a/library/cpp/string_utils/quote/quote.cpp +++ b/library/cpp/string_utils/quote/quote.cpp @@ -302,10 +302,10 @@ void UrlEscape(TString& url, bool forceEscape) { char* to = tempBuf.Data(); url.AssignNoAlias(to, UrlEscape(to, url.data(), forceEscape)); } - -TString UrlEscapeRet(const TStringBuf from, bool forceEscape) { - TString to; + +TString UrlEscapeRet(const TStringBuf from, bool forceEscape) { + TString to; to.ReserveAndResize(CgiEscapeBufLen(from.size())); to.resize(UrlEscape(to.begin(), from.begin(), forceEscape) - to.data()); - return to; -} + return to; +} diff --git a/library/cpp/string_utils/quote/quote.h b/library/cpp/string_utils/quote/quote.h index 3b7221154e..1d3d86f351 100644 --- a/library/cpp/string_utils/quote/quote.h +++ b/library/cpp/string_utils/quote/quote.h @@ -53,7 +53,7 @@ void Quote(TString& url, const char* safe = "/"); // Can't handle '\0'-chars in TString. char* UrlEscape(char* to, const char* from, bool forceEscape = false); void UrlEscape(TString& url, bool forceEscape = false); -TString UrlEscapeRet(const TStringBuf from, bool forceEscape = false); +TString UrlEscapeRet(const TStringBuf from, bool forceEscape = false); //UrlUnescape: // '+' is NOT converted to space! diff --git a/library/cpp/string_utils/quote/quote_ut.cpp b/library/cpp/string_utils/quote/quote_ut.cpp index 6c552b279e..6a889f0a07 100644 --- a/library/cpp/string_utils/quote/quote_ut.cpp +++ b/library/cpp/string_utils/quote/quote_ut.cpp @@ -183,7 +183,7 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { TString s; s = "hello%3dworld"; - UNIT_ASSERT_VALUES_EQUAL(UrlEscapeRet(s), "hello%3dworld"); + UNIT_ASSERT_VALUES_EQUAL(UrlEscapeRet(s), "hello%3dworld"); UrlEscape(s); UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); } @@ -197,18 +197,18 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { UNIT_ASSERT_VALUES_EQUAL(s, "hello=world"); } - Y_UNIT_TEST(EscapeUnescapeRet) { - TString s; - - s = "hello%3dworld"; - UNIT_ASSERT_VALUES_EQUAL(UrlUnescapeRet(UrlEscapeRet(s)), "hello=world"); - } - + Y_UNIT_TEST(EscapeUnescapeRet) { + TString s; + + s = "hello%3dworld"; + UNIT_ASSERT_VALUES_EQUAL(UrlUnescapeRet(UrlEscapeRet(s)), "hello=world"); + } + Y_UNIT_TEST(EscapeEscapedForce) { TString s; s = "hello%3dworld"; - UNIT_ASSERT_VALUES_EQUAL(UrlEscapeRet(s, true), "hello%253dworld"); + UNIT_ASSERT_VALUES_EQUAL(UrlEscapeRet(s, true), "hello%253dworld"); UrlEscape(s, true); UNIT_ASSERT_VALUES_EQUAL(s, "hello%253dworld"); } @@ -221,13 +221,13 @@ Y_UNIT_TEST_SUITE(TUrlEscapeTest) { UrlUnescape(s); UNIT_ASSERT_VALUES_EQUAL(s, "hello%3dworld"); } - - Y_UNIT_TEST(EscapeUnescapeForceRet) { - TString s; - - s = "hello%3dworld"; - UNIT_ASSERT_VALUES_EQUAL(UrlUnescapeRet(UrlEscapeRet(s, true)), "hello%3dworld"); - } + + Y_UNIT_TEST(EscapeUnescapeForceRet) { + TString s; + + s = "hello%3dworld"; + UNIT_ASSERT_VALUES_EQUAL(UrlUnescapeRet(UrlEscapeRet(s, true)), "hello%3dworld"); + } } Y_UNIT_TEST_SUITE(TUrlUnescapeTest) { diff --git a/library/cpp/yson/node/node.cpp b/library/cpp/yson/node/node.cpp index b39e070718..a6b73d8933 100644 --- a/library/cpp/yson/node/node.cpp +++ b/library/cpp/yson/node/node.cpp @@ -22,75 +22,75 @@ bool TNode::TUndefined::operator==(const TUndefined&) const { //////////////////////////////////////////////////////////////////////////////// -namespace NNodeCmp { - -bool IsComparableType(const TNode::EType type) { - switch (type) { - case TNode::String: - case TNode::Int64: - case TNode::Uint64: - case TNode::Double: - case TNode::Bool: - case TNode::Null: - case TNode::Undefined: - return true; - default: - return false; - } -} - -bool operator<(const TNode& lhs, const TNode& rhs) -{ - if (!lhs.GetAttributes().Empty() || !rhs.GetAttributes().Empty()) { - ythrow TNode::TTypeError() << "Unsupported attributes comparison"; - } - - if (!IsComparableType(lhs.GetType()) || !IsComparableType(rhs.GetType())) { - ythrow TNode::TTypeError() << "Unsupported types for comparison: " << lhs.GetType() << " with " << rhs.GetType(); - } - - if (lhs.GetType() != rhs.GetType()) { - return lhs.GetType() < rhs.GetType(); - } - - switch (lhs.GetType()) { - case TNode::String: - return lhs.AsString() < rhs.AsString(); - case TNode::Int64: - return lhs.AsInt64() < rhs.AsInt64(); - case TNode::Uint64: - return lhs.AsUint64() < rhs.AsUint64(); - case TNode::Double: - return lhs.AsDouble() < rhs.AsDouble(); - case TNode::Bool: - return lhs.AsBool() < rhs.AsBool(); - case TNode::Null: - case TNode::Undefined: - return false; - default: - Y_FAIL("Unexpected type: %d", lhs.GetType()); - } -} - -bool operator>(const TNode& lhs, const TNode& rhs) -{ - return rhs < lhs; -} - -bool operator<=(const TNode& lhs, const TNode& rhs) -{ - return !(lhs > rhs); -} - -bool operator>=(const TNode& lhs, const TNode& rhs) -{ - return !(lhs < rhs); -} - -} // namespace NNodeCmp - -//////////////////////////////////////////////////////////////////////////////// - +namespace NNodeCmp { + +bool IsComparableType(const TNode::EType type) { + switch (type) { + case TNode::String: + case TNode::Int64: + case TNode::Uint64: + case TNode::Double: + case TNode::Bool: + case TNode::Null: + case TNode::Undefined: + return true; + default: + return false; + } +} + +bool operator<(const TNode& lhs, const TNode& rhs) +{ + if (!lhs.GetAttributes().Empty() || !rhs.GetAttributes().Empty()) { + ythrow TNode::TTypeError() << "Unsupported attributes comparison"; + } + + if (!IsComparableType(lhs.GetType()) || !IsComparableType(rhs.GetType())) { + ythrow TNode::TTypeError() << "Unsupported types for comparison: " << lhs.GetType() << " with " << rhs.GetType(); + } + + if (lhs.GetType() != rhs.GetType()) { + return lhs.GetType() < rhs.GetType(); + } + + switch (lhs.GetType()) { + case TNode::String: + return lhs.AsString() < rhs.AsString(); + case TNode::Int64: + return lhs.AsInt64() < rhs.AsInt64(); + case TNode::Uint64: + return lhs.AsUint64() < rhs.AsUint64(); + case TNode::Double: + return lhs.AsDouble() < rhs.AsDouble(); + case TNode::Bool: + return lhs.AsBool() < rhs.AsBool(); + case TNode::Null: + case TNode::Undefined: + return false; + default: + Y_FAIL("Unexpected type: %d", lhs.GetType()); + } +} + +bool operator>(const TNode& lhs, const TNode& rhs) +{ + return rhs < lhs; +} + +bool operator<=(const TNode& lhs, const TNode& rhs) +{ + return !(lhs > rhs); +} + +bool operator>=(const TNode& lhs, const TNode& rhs) +{ + return !(lhs < rhs); +} + +} // namespace NNodeCmp + +//////////////////////////////////////////////////////////////////////////////// + TNode::TNode() : Value_(TUndefined{}) { } diff --git a/library/cpp/yson/node/node.h b/library/cpp/yson/node/node.h index 5f90f95df0..7217edba83 100644 --- a/library/cpp/yson/node/node.h +++ b/library/cpp/yson/node/node.h @@ -510,14 +510,14 @@ inline const T& TNode::As() const { //////////////////////////////////////////////////////////////////////////////// -namespace NNodeCmp { - bool operator<(const TNode& lhs, const TNode& rhs); - bool operator<=(const TNode& lhs, const TNode& rhs); - bool operator>(const TNode& lhs, const TNode& rhs); - bool operator>=(const TNode& lhs, const TNode& rhs); - bool IsComparableType(const TNode::EType type); -} - -//////////////////////////////////////////////////////////////////////////////// - +namespace NNodeCmp { + bool operator<(const TNode& lhs, const TNode& rhs); + bool operator<=(const TNode& lhs, const TNode& rhs); + bool operator>(const TNode& lhs, const TNode& rhs); + bool operator>=(const TNode& lhs, const TNode& rhs); + bool IsComparableType(const TNode::EType type); +} + +//////////////////////////////////////////////////////////////////////////////// + } // namespace NYT diff --git a/library/cpp/yson/node/node_ut.cpp b/library/cpp/yson/node/node_ut.cpp index 448e99f575..c862fdb20a 100644 --- a/library/cpp/yson/node/node_ut.cpp +++ b/library/cpp/yson/node/node_ut.cpp @@ -196,70 +196,70 @@ Y_UNIT_TEST_SUITE(YtNodeTest) { UNIT_ASSERT(node == copyNode); } - Y_UNIT_TEST(TestComparison) { - using namespace NYT::NNodeCmp; - { - TNode nodeNoAttributes = TNode()("lee", 42)("faa", 54); - TNode node = nodeNoAttributes; - node.Attributes()("foo", true)("bar", false); - UNIT_ASSERT_EXCEPTION(node > nodeNoAttributes, TNode::TTypeError); - UNIT_ASSERT_EXCEPTION(node >= nodeNoAttributes, TNode::TTypeError); - UNIT_ASSERT_EXCEPTION(nodeNoAttributes < node, TNode::TTypeError); - UNIT_ASSERT_EXCEPTION(nodeNoAttributes <= node, TNode::TTypeError); - } - { - TNode nodeMap = TNode()("map", 23); - TNode nodeList = TNode::CreateList(); - UNIT_ASSERT_EXCEPTION(nodeList > nodeMap, TNode::TTypeError); - UNIT_ASSERT_EXCEPTION(nodeMap < nodeList, TNode::TTypeError); - UNIT_ASSERT_EXCEPTION(nodeMap >= nodeMap, TNode::TTypeError); - UNIT_ASSERT_EXCEPTION(nodeList <= nodeList, TNode::TTypeError); - } - { - TNode node1("aaa"); - TNode node2("bbb"); - TNode node3("ccc"); - UNIT_ASSERT(node1 < node2); - UNIT_ASSERT(node1 <= node2); - UNIT_ASSERT(node1 < node3); - UNIT_ASSERT(node1 <= node3); - UNIT_ASSERT(!(node3 < node1)); - UNIT_ASSERT(!(node1 > node3)); - UNIT_ASSERT(!(node3 <= node1)); - UNIT_ASSERT(!(node1 >= node3)); - - UNIT_ASSERT(node3 > node2); - UNIT_ASSERT(node3 >= node2); - UNIT_ASSERT(node3 > node1); - UNIT_ASSERT(node3 >= node1); - - UNIT_ASSERT(node1 <= node1); - UNIT_ASSERT(node1 >= node1); - } - { - TNode node1(23); - TNode node2("bbb"); - TNode node3 = TNode::CreateEntity(); - - UNIT_ASSERT(node1 > node2); - UNIT_ASSERT(node1 >= node2); - UNIT_ASSERT(node2 < node1); - UNIT_ASSERT(node2 <= node1); - - UNIT_ASSERT(!(node1 < node2)); - UNIT_ASSERT(!(node1 <= node2)); - UNIT_ASSERT(!(node2 > node1)); - UNIT_ASSERT(!(node2 >= node1)); - - UNIT_ASSERT(node1 < node3); - UNIT_ASSERT(node2 < node3); - UNIT_ASSERT(node3 <= node3); - UNIT_ASSERT(!(node3 < node3)); - UNIT_ASSERT(!(node3 > node3)); - UNIT_ASSERT(!(node2 >= node3)); - } - } - + Y_UNIT_TEST(TestComparison) { + using namespace NYT::NNodeCmp; + { + TNode nodeNoAttributes = TNode()("lee", 42)("faa", 54); + TNode node = nodeNoAttributes; + node.Attributes()("foo", true)("bar", false); + UNIT_ASSERT_EXCEPTION(node > nodeNoAttributes, TNode::TTypeError); + UNIT_ASSERT_EXCEPTION(node >= nodeNoAttributes, TNode::TTypeError); + UNIT_ASSERT_EXCEPTION(nodeNoAttributes < node, TNode::TTypeError); + UNIT_ASSERT_EXCEPTION(nodeNoAttributes <= node, TNode::TTypeError); + } + { + TNode nodeMap = TNode()("map", 23); + TNode nodeList = TNode::CreateList(); + UNIT_ASSERT_EXCEPTION(nodeList > nodeMap, TNode::TTypeError); + UNIT_ASSERT_EXCEPTION(nodeMap < nodeList, TNode::TTypeError); + UNIT_ASSERT_EXCEPTION(nodeMap >= nodeMap, TNode::TTypeError); + UNIT_ASSERT_EXCEPTION(nodeList <= nodeList, TNode::TTypeError); + } + { + TNode node1("aaa"); + TNode node2("bbb"); + TNode node3("ccc"); + UNIT_ASSERT(node1 < node2); + UNIT_ASSERT(node1 <= node2); + UNIT_ASSERT(node1 < node3); + UNIT_ASSERT(node1 <= node3); + UNIT_ASSERT(!(node3 < node1)); + UNIT_ASSERT(!(node1 > node3)); + UNIT_ASSERT(!(node3 <= node1)); + UNIT_ASSERT(!(node1 >= node3)); + + UNIT_ASSERT(node3 > node2); + UNIT_ASSERT(node3 >= node2); + UNIT_ASSERT(node3 > node1); + UNIT_ASSERT(node3 >= node1); + + UNIT_ASSERT(node1 <= node1); + UNIT_ASSERT(node1 >= node1); + } + { + TNode node1(23); + TNode node2("bbb"); + TNode node3 = TNode::CreateEntity(); + + UNIT_ASSERT(node1 > node2); + UNIT_ASSERT(node1 >= node2); + UNIT_ASSERT(node2 < node1); + UNIT_ASSERT(node2 <= node1); + + UNIT_ASSERT(!(node1 < node2)); + UNIT_ASSERT(!(node1 <= node2)); + UNIT_ASSERT(!(node2 > node1)); + UNIT_ASSERT(!(node2 >= node1)); + + UNIT_ASSERT(node1 < node3); + UNIT_ASSERT(node2 < node3); + UNIT_ASSERT(node3 <= node3); + UNIT_ASSERT(!(node3 < node3)); + UNIT_ASSERT(!(node3 > node3)); + UNIT_ASSERT(!(node2 >= node3)); + } + } + Y_UNIT_TEST(TestSaveLoad) { TNode node = TNode()("foo", "bar")("baz", 42); node.Attributes()["attr_name"] = "attr_value"; |