diff options
| author | Vlad Yaroslavlev <[email protected]> | 2022-02-10 16:46:23 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:46:23 +0300 | 
| commit | 706b83ed7de5a473436620367af31fc0ceecde07 (patch) | |
| tree | 103305d30dec77e8f6367753367f59b3cd68f9f1 /library/cpp/xml/document | |
| parent | 918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (diff) | |
Restoring authorship annotation for Vlad Yaroslavlev <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/xml/document')
| -rw-r--r-- | library/cpp/xml/document/README | 10 | ||||
| -rw-r--r-- | library/cpp/xml/document/node-attr.h | 2 | ||||
| -rw-r--r-- | library/cpp/xml/document/xml-document-decl.h | 18 | ||||
| -rw-r--r-- | library/cpp/xml/document/xml-document.cpp | 2 | ||||
| -rw-r--r-- | library/cpp/xml/document/xml-document_ut.cpp | 40 | ||||
| -rw-r--r-- | library/cpp/xml/document/xml-textreader.cpp | 20 | ||||
| -rw-r--r-- | library/cpp/xml/document/xml-textreader.h | 14 | ||||
| -rw-r--r-- | library/cpp/xml/document/xml-textreader_ut.cpp | 56 | 
8 files changed, 81 insertions, 81 deletions
| diff --git a/library/cpp/xml/document/README b/library/cpp/xml/document/README index b2649523d8f..164d3a1c9c3 100644 --- a/library/cpp/xml/document/README +++ b/library/cpp/xml/document/README @@ -16,9 +16,9 @@ The standard way to use it is as follows:          using namespace NXml;          TConstNode& node = nodes[i];          // query node -        TString name = node.Name(); -        TString lang = node.Attr<TString>("lang"); -        TString text = node.Value<TString>(); +        TString name = node.Name();  +        TString lang = node.Attr<TString>("lang");  +        TString text = node.Value<TString>();           TConstNode child = node.GetFirstChild("");          // edit node          TNode node = child.ConstCast(); @@ -34,9 +34,9 @@ The standard way to use it is as follows:      // copy node's subtree from one document to another      place.AddChild(xml.Root());      // save (render) single element -    TString modifiedNode = place.ToString(); +    TString modifiedNode = place.ToString();       // save whole document with optional encoding -    TString modifiedDoc  = xml2.ToString("ISO-8559-1"); +    TString modifiedDoc  = xml2.ToString("ISO-8559-1");   See xml-document_ut.cpp for more examples. diff --git a/library/cpp/xml/document/node-attr.h b/library/cpp/xml/document/node-attr.h index 6e74403943c..6321fcb2671 100644 --- a/library/cpp/xml/document/node-attr.h +++ b/library/cpp/xml/document/node-attr.h @@ -28,7 +28,7 @@ namespace NXml {      template <>      inline void TNode::AttrInternal(TCharPtr& value, TString& res, TStringBuf /*errContext*/) const { -        TString tmp(CAST2CHAR(value.Get())); +        TString tmp(CAST2CHAR(value.Get()));           res.swap(tmp);      } diff --git a/library/cpp/xml/document/xml-document-decl.h b/library/cpp/xml/document/xml-document-decl.h index bfda1fb7e6e..b481d8164cd 100644 --- a/library/cpp/xml/document/xml-document-decl.h +++ b/library/cpp/xml/document/xml-document-decl.h @@ -2,7 +2,7 @@  #include <library/cpp/string_utils/ztstrbuf/ztstrbuf.h> -#include <util/generic/string.h> +#include <util/generic/string.h>   #include <util/generic/vector.h>  #include <util/stream/output.h>  #include <util/stream/str.h> @@ -32,7 +32,7 @@ namespace NXml {          * @param src: source type: File | String | RootName          * throws if file not found or cannot be parsed          */ -        TDocument(const TString& source, Source type = File); +        TDocument(const TString& source, Source type = File);       public:          TDocument(const TDocument& that) = delete; @@ -71,7 +71,7 @@ namespace NXml {          }      private: -        void ParseFile(const TString& file); +        void ParseFile(const TString& file);           void ParseString(TZtStringBuf xml);          TDocument(TDocHolder doc) @@ -83,10 +83,10 @@ namespace NXml {      };      struct TNamespaceForXPath { -        TString Prefix; -        TString Url; +        TString Prefix;  +        TString Url;       }; -    typedef TVector<TNamespaceForXPath> TNamespacesForXPath; +    typedef TVector<TNamespaceForXPath> TNamespacesForXPath;       class TConstNodes {      private: @@ -411,12 +411,12 @@ namespace NXml {          /**          * get node name          */ -        TString Name() const; +        TString Name() const;           /**          * get node xpath          */ -        TString Path() const; +        TString Path() const;           /**          * get node xml representation @@ -662,7 +662,7 @@ namespace NXml {          /**          * get node name          */ -        TString Name() const { +        TString Name() const {               return ActualNode.Name();          } diff --git a/library/cpp/xml/document/xml-document.cpp b/library/cpp/xml/document/xml-document.cpp index 18a554d7321..17e7f784242 100644 --- a/library/cpp/xml/document/xml-document.cpp +++ b/library/cpp/xml/document/xml-document.cpp @@ -270,7 +270,7 @@ namespace NXml {          return TNode();      } -    TString TNode::Name() const { +    TString TNode::Name() const {           if (IsNull())              THROW(XmlException, "Node is null"); diff --git a/library/cpp/xml/document/xml-document_ut.cpp b/library/cpp/xml/document/xml-document_ut.cpp index 9f537b75c4c..c56d2110593 100644 --- a/library/cpp/xml/document/xml-document_ut.cpp +++ b/library/cpp/xml/document/xml-document_ut.cpp @@ -33,7 +33,7 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {          UNIT_ASSERT_EQUAL(b.Attr<bool>("correct"), true);          NXml::TConstNode text = root.Node("text"); -        UNIT_ASSERT_EQUAL(text.Value<TString>(), "Некоторый текст"); +        UNIT_ASSERT_EQUAL(text.Value<TString>(), "Некоторый текст");       }      Y_UNIT_TEST(SerializeString) {          NXml::TDocument xml("frob", NXml::TDocument::RootName); @@ -46,7 +46,7 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {          authors.AddChild("zarf").SetValue("Andrew Plotkin");          authors.AddChild("emshort", "Emily Short"); -        TString data = xml.ToString("utf-8"); +        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"                                  "  <authors>\n" @@ -57,9 +57,9 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {                                  "</frob>\n");          // check default utf8 output with ru          { -            NXml::TDocument xml2("frob", NXml::TDocument::RootName); -            xml2.Root().SetAttr("xyzzy", "привет =)"); -            UNIT_ASSERT_VALUES_EQUAL(xml2.ToString(), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +            NXml::TDocument xml2("frob", NXml::TDocument::RootName);  +            xml2.Root().SetAttr("xyzzy", "привет =)");  +            UNIT_ASSERT_VALUES_EQUAL(xml2.ToString(), "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"                                                         "<frob xyzzy=\"привет =)\"/>\n");          }      } @@ -83,13 +83,13 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {          UNIT_ASSERT_EQUAL(b.Attr<bool>("correct"), true);          TConstNode text = root.Node("h:text", false, nss); -        UNIT_ASSERT_EQUAL(text.Value<TString>(), "Некоторый текст"); +        UNIT_ASSERT_EQUAL(text.Value<TString>(), "Некоторый текст");           // For performance you can create xpath context once using nss and pass it.          TXPathContextPtr ctxt = root.CreateXPathContext(nss);          UNIT_ASSERT(root.Node("text", true, *ctxt).IsNull());          UNIT_ASSERT_EXCEPTION(root.Node("text", false, *ctxt), yexception); -        UNIT_ASSERT_EQUAL(root.Node("h:text", false, *ctxt).Value<TString>(), "Некоторый текст"); +        UNIT_ASSERT_EQUAL(root.Node("h:text", false, *ctxt).Value<TString>(), "Некоторый текст");       }      Y_UNIT_TEST(XmlNodes) {          using namespace NXml; @@ -97,34 +97,34 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {                        "<root>qq<a><b>asdfg</b></a>ww<c></c></root>",                        NXml::TDocument::String);          TNode root = xml.Root(); -        UNIT_ASSERT_EQUAL(root.Value<TString>(), "qqasdfgww"); +        UNIT_ASSERT_EQUAL(root.Value<TString>(), "qqasdfgww");           TConstNode node = root.FirstChild();          UNIT_ASSERT_EQUAL(node.IsText(), true); -        UNIT_ASSERT_EQUAL(node.Value<TString>(), "qq"); +        UNIT_ASSERT_EQUAL(node.Value<TString>(), "qq");           node = node.NextSibling();          UNIT_ASSERT_EQUAL(node.IsText(), false);          UNIT_ASSERT_EQUAL(node.Name(), "a"); -        UNIT_ASSERT_EQUAL(node.Value<TString>(), "asdfg"); +        UNIT_ASSERT_EQUAL(node.Value<TString>(), "asdfg");           node = node.NextSibling();          UNIT_ASSERT_EQUAL(node.IsText(), true); -        UNIT_ASSERT_EQUAL(node.Value<TString>(), "ww"); +        UNIT_ASSERT_EQUAL(node.Value<TString>(), "ww");           node = node.NextSibling();          UNIT_ASSERT_EQUAL(node.IsText(), false);          UNIT_ASSERT_EQUAL(node.Name(), "c"); -        UNIT_ASSERT_EQUAL(node.Value<TString>(), ""); +        UNIT_ASSERT_EQUAL(node.Value<TString>(), "");           node = node.NextSibling();          UNIT_ASSERT_EQUAL(node.IsNull(), true);          TStringStream iterLog;          for (const auto& node2 : root.Nodes("/root/*")) { -            iterLog << node2.Name() << ';'; +            iterLog << node2.Name() << ';';           }          UNIT_ASSERT_STRINGS_EQUAL(iterLog.Str(), "a;c;");          // get only element nodes, ignore text nodes with empty "name" param -        node = root.FirstChild(TString()); +        node = root.FirstChild(TString());           UNIT_ASSERT_EQUAL(node.IsText(), false);          UNIT_ASSERT_EQUAL(node.Name(), "a"); -        node = node.NextSibling(TString()); +        node = node.NextSibling(TString());           UNIT_ASSERT_EQUAL(node.IsText(), false);          UNIT_ASSERT_EQUAL(node.Name(), "c"); @@ -148,7 +148,7 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {          node = root.NextSibling("unknownnode");          UNIT_ASSERT_EQUAL(node.IsNull(), true);          UNIT_ASSERT_EXCEPTION(node.Name(), yexception); -        UNIT_ASSERT_EXCEPTION(node.Value<TString>(), yexception); +        UNIT_ASSERT_EXCEPTION(node.Value<TString>(), yexception);           UNIT_ASSERT_EXCEPTION(node.IsText(), yexception);      }      Y_UNIT_TEST(DefVal) { @@ -173,14 +173,14 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {                        "<a>second</a></root>",                        NXml::TDocument::String);          UNIT_ASSERT_EXCEPTION(xml.Root().Node("/root/a/@x"), yexception); -        UNIT_ASSERT_STRINGS_EQUAL(xml.Root().Node("/root/a").Value<TString>(), "first"); +        UNIT_ASSERT_STRINGS_EQUAL(xml.Root().Node("/root/a").Value<TString>(), "first");       }      Y_UNIT_TEST(CopyNode) {          using namespace NXml;          // default-construct empty node          TNode empty;          // put to container -        TMap<int, TNode> nmap; +        TMap<int, TNode> nmap;           nmap[2];          // do copy @@ -255,11 +255,11 @@ Y_UNIT_TEST_SUITE(TestXmlDocument) {          // We can use root node context for xpath evaluation in any node          TConstNode c1 = b.Node("c", false, *rootCtxt); -        UNIT_ASSERT_EQUAL(c1.Value<TString>(), "Hello, world!"); +        UNIT_ASSERT_EQUAL(c1.Value<TString>(), "Hello, world!");           TXPathContextPtr bCtxt = b.CreateXPathContext();          TConstNode c2 = b.Node("c", false, *bCtxt); -        UNIT_ASSERT_EQUAL(c2.Value<TString>(), "Hello, world!"); +        UNIT_ASSERT_EQUAL(c2.Value<TString>(), "Hello, world!");           // Mixing contexts from different documents is forbidden          TDocument otherXml("<root></root>", TDocument::String); diff --git a/library/cpp/xml/document/xml-textreader.cpp b/library/cpp/xml/document/xml-textreader.cpp index b946f1fbf2f..f7d64670c83 100644 --- a/library/cpp/xml/document/xml-textreader.cpp +++ b/library/cpp/xml/document/xml-textreader.cpp @@ -27,15 +27,15 @@ namespace NXml {          return BoolResult(xmlTextReaderRead(Impl.Get()));      } -    TString TTextReader::ReadInnerXml() const { +    TString TTextReader::ReadInnerXml() const {           return TempStringOrEmptyResult(xmlTextReaderReadInnerXml(Impl.Get()));      } -    TString TTextReader::ReadOuterXml() const { +    TString TTextReader::ReadOuterXml() const {           return TempStringOrEmptyResult(xmlTextReaderReadOuterXml(Impl.Get()));      } -    TString TTextReader::ReadString() const { +    TString TTextReader::ReadString() const {           return TempStringOrEmptyResult(xmlTextReaderReadString(Impl.Get()));      } @@ -109,7 +109,7 @@ namespace NXml {          }      } -    TString TTextReader::GetAttribute(int number) const { +    TString TTextReader::GetAttribute(int number) const {           return TempStringResult(xmlTextReaderGetAttributeNo(Impl.Get(), number));      } @@ -166,7 +166,7 @@ namespace NXml {      }      // Callback for xmlReaderForIO() to read more data. -    // It is almost "noexcept" (std::bad_alloc may happen when saving exception message to new TString). +    // It is almost "noexcept" (std::bad_alloc may happen when saving exception message to new TString).       // Waiting for std::exception_ptr and std::rethrow_exception from C++11 in Arcadia to make it really "noexcept".      int TTextReader::ReadFromInputStreamCallback(void* context, char* buffer, int len) {          Y_ASSERT(len >= 0); @@ -251,7 +251,7 @@ namespace NXml {              return;          } -        const TString message = ErrorBuffer.Str(); +        const TString message = ErrorBuffer.Str();           ErrorBuffer.clear();          IsError = false; @@ -298,16 +298,16 @@ namespace NXml {          return (value != nullptr) ? TStringBuf(CAST2CHAR(value)) : TStringBuf();      } -    TString TTextReader::TempStringResult(TCharPtr value) const { +    TString TTextReader::TempStringResult(TCharPtr value) const {           if (Y_UNLIKELY(value == nullptr)) {              ThrowException();          } -        return TString(CAST2CHAR(value.Get())); +        return TString(CAST2CHAR(value.Get()));       } -    TString TTextReader::TempStringOrEmptyResult(TCharPtr value) const { +    TString TTextReader::TempStringOrEmptyResult(TCharPtr value) const {           CheckForExceptions(); -        return (value != nullptr) ? TString(CAST2CHAR(value.Get())) : TString(); +        return (value != nullptr) ? TString(CAST2CHAR(value.Get())) : TString();       }      struct TTextReader::TDeleter { diff --git a/library/cpp/xml/document/xml-textreader.h b/library/cpp/xml/document/xml-textreader.h index ab4c329d26d..f0cba3182c4 100644 --- a/library/cpp/xml/document/xml-textreader.h +++ b/library/cpp/xml/document/xml-textreader.h @@ -10,7 +10,7 @@  #include <util/generic/noncopyable.h>  #include <util/generic/ptr.h>  #include <util/generic/strbuf.h> -#include <util/generic/string.h> +#include <util/generic/string.h>   #include <functional>  #include <util/stream/input.h>  #include <util/stream/str.h> @@ -91,21 +91,21 @@ namespace NXml {           * @return A string containing the XML content, or an empty string           *         if the current node is neither an element nor attribute, or has no child nodes           */ -        TString ReadInnerXml() const; +        TString ReadInnerXml() const;           /**           * Reads the current node and its contents, including child nodes and markup.           * @return A string containing the XML content, or an empty string           *         if the current node is neither an element nor attribute           */ -        TString ReadOuterXml() const; +        TString ReadOuterXml() const;           /**           * Reads the contents of an element or a text node as a string.           * @return A string containing the contents of the Element or Text node,           *         or an empty string if the reader is positioned on any other type of node           */ -        TString ReadString() const; +        TString ReadString() const;           /**           * Parses an attribute value into one or more Text and EntityReference nodes. @@ -216,7 +216,7 @@ namespace NXml {           * Provides the value of the attribute with the specified index relative to the containing element.           * @param number the zero-based index of the attribute relative to the containing element           */ -        TString GetAttribute(int number) const; +        TString GetAttribute(int number) const;           /**           * Provides the value of the attribute with the specified qualified name. @@ -309,8 +309,8 @@ namespace NXml {          char CharResult(int value) const;          TStringBuf ConstStringResult(const xmlChar* value) const;          TStringBuf ConstStringOrEmptyResult(const xmlChar* value) const; -        TString TempStringResult(TCharPtr value) const; -        TString TempStringOrEmptyResult(TCharPtr value) const; +        TString TempStringResult(TCharPtr value) const;  +        TString TempStringOrEmptyResult(TCharPtr value) const;       private:          IInputStream& Stream; diff --git a/library/cpp/xml/document/xml-textreader_ut.cpp b/library/cpp/xml/document/xml-textreader_ut.cpp index 6232dfe47e2..32558b95e6a 100644 --- a/library/cpp/xml/document/xml-textreader_ut.cpp +++ b/library/cpp/xml/document/xml-textreader_ut.cpp @@ -10,10 +10,10 @@ namespace {      /**       * Simple wrapper around the xmlTextReader wrapper       */ -    void ParseXml(const TString& xmlData, +    void ParseXml(const TString& xmlData,                     std::function<void(NXml::TConstNode)> nodeHandlerFunc, -                  const TString& localName, -                  const TString& namespaceUri = TString()) { +                  const TString& localName,  +                  const TString& namespaceUri = TString()) {           TStringInput in(xmlData);          NXml::TTextReader reader(in); @@ -31,7 +31,7 @@ namespace {  Y_UNIT_TEST_SUITE(TestXmlTextReader) {      Y_UNIT_TEST(BasicExample) { -        const TString xml = "<?xml version=\"1.0\"?>\n" +        const TString xml = "<?xml version=\"1.0\"?>\n"                               "<example toto=\"1\">\n"                              "  <examplechild id=\"1\">\n"                              "    <child_of_child/>\n" @@ -49,21 +49,21 @@ Y_UNIT_TEST_SUITE(TestXmlTextReader) {          struct TItem {              int Depth;              ENT Type; -            TString Name; -            TString Attrs; -            TString Value; +            TString Name;  +            TString Attrs;  +            TString Value;           }; -        TVector<TItem> found; -        TVector<TString> msgs; +        TVector<TItem> found;  +        TVector<TString> msgs;           while (reader.Read()) {              // dump attributes as "k1: v1, k2: v2, ..." -            TVector<TString> kv; +            TVector<TString> kv;               if (reader.HasAttributes()) {                  reader.MoveToFirstAttribute();                  do { -                    kv.push_back(TString::Join(reader.GetName(), ": ", reader.GetValue())); +                    kv.push_back(TString::Join(reader.GetName(), ": ", reader.GetValue()));                   } while (reader.MoveToNextAttribute());                  reader.MoveToElement();              } @@ -71,13 +71,13 @@ Y_UNIT_TEST_SUITE(TestXmlTextReader) {              found.push_back(TItem{                  reader.GetDepth(),                  reader.GetNodeType(), -                TString(reader.GetName()), +                TString(reader.GetName()),                   JoinSeq(", ", kv), -                reader.HasValue() ? TString(reader.GetValue()) : TString(), +                reader.HasValue() ? TString(reader.GetValue()) : TString(),               });          } -        const TVector<TItem> expected = { +        const TVector<TItem> expected = {               TItem{0, ENT::Element, "example", "toto: 1", ""},              TItem{1, ENT::SignificantWhitespace, "#text", "", "\n  "},              TItem{1, ENT::Element, "examplechild", "id: 1", ""}, @@ -107,7 +107,7 @@ Y_UNIT_TEST_SUITE(TestXmlTextReader) {          }      } -    const TString GEODATA = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +    const TString GEODATA = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"                               "<root>"                              ""                              "  <country id=\"225\">" @@ -136,22 +136,22 @@ Y_UNIT_TEST_SUITE(TestXmlTextReader) {      Y_UNIT_TEST(ParseXmlSimple) {          struct TCountry { -            TString Name; -            TVector<TString> Cities; +            TString Name;  +            TVector<TString> Cities;           }; -        THashMap<int, TCountry> data; +        THashMap<int, TCountry> data;           auto handler = [&data](NXml::TConstNode node) {              const int id = node.Attr<int>("id");              TCountry& c = data[id]; -            c.Name = node.FirstChild("name").Value<TString>(); +            c.Name = node.FirstChild("name").Value<TString>();               const NXml::TConstNodes cityNodes = node.Nodes("cities/city");              for (auto cityNode : cityNodes) { -                c.Cities.push_back(cityNode.Value<TString>()); +                c.Cities.push_back(cityNode.Value<TString>());               }          }; @@ -180,10 +180,10 @@ Y_UNIT_TEST_SUITE(TestXmlTextReader) {      }      Y_UNIT_TEST(ParseXmlDeepLevel) { -        TVector<TString> cities; +        TVector<TString> cities;           auto handler = [&cities](NXml::TConstNode node) { -            cities.push_back(node.Value<TString>()); +            cities.push_back(node.Value<TString>());           };          ParseXml(GEODATA, handler, "city"); @@ -211,7 +211,7 @@ Y_UNIT_TEST_SUITE(TestXmlTextReader) {          UNIT_ASSERT_EXCEPTION(ParseXml("<root><a id=\"1\"></a><a id=\"2></a></root>", handler, "a"), yexception);      } -    const TString BACKA = // UTF-8 encoding is used implicitly +    const TString BACKA = // UTF-8 encoding is used implicitly           "<Companies"          "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""          "    xmlns=\"http://maps.yandex.ru/backa/1.x\"" @@ -259,18 +259,18 @@ Y_UNIT_TEST_SUITE(TestXmlTextReader) {              TNS{"xal", "urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"}};          int count = 0; -        THashMap<TString, TString> positions; -        THashMap<TString, TString> addresses; +        THashMap<TString, TString> positions;  +        THashMap<TString, TString> addresses;           auto handler = [&](NXml::TConstNode node) {              count++; -            const auto id = node.Attr<TString>("id"); +            const auto id = node.Attr<TString>("id");               NXml::TXPathContextPtr ctxt = node.CreateXPathContext(ns);              const NXml::TConstNode location = node.Node("b:Geo/b:Location", false, *ctxt); -            positions[id] = location.Node("gml:pos", false, *ctxt).Value<TString>(); -            addresses[id] = node.Node("b:Geo/xal:AddressDetails/xal:Country/xal:AddressLine", false, *ctxt).Value<TString>(); +            positions[id] = location.Node("gml:pos", false, *ctxt).Value<TString>();  +            addresses[id] = node.Node("b:Geo/xal:AddressDetails/xal:Country/xal:AddressLine", false, *ctxt).Value<TString>();           };          ParseXml(BACKA, handler, "Company"); | 
