diff options
author | orivej <orivej@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:49 +0300 |
commit | 718c552901d703c502ccbefdfc3c9028d608b947 (patch) | |
tree | 46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/poco/XML/src/NodeIterator.cpp | |
parent | e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff) | |
download | ydb-718c552901d703c502ccbefdfc3c9028d608b947.tar.gz |
Restoring authorship annotation for <orivej@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/poco/XML/src/NodeIterator.cpp')
-rw-r--r-- | contrib/libs/poco/XML/src/NodeIterator.cpp | 352 |
1 files changed, 176 insertions, 176 deletions
diff --git a/contrib/libs/poco/XML/src/NodeIterator.cpp b/contrib/libs/poco/XML/src/NodeIterator.cpp index 69685f9f4e..40a97acf89 100644 --- a/contrib/libs/poco/XML/src/NodeIterator.cpp +++ b/contrib/libs/poco/XML/src/NodeIterator.cpp @@ -1,176 +1,176 @@ -// -// NodeIterator.cpp -// -// Library: XML -// Package: DOM -// Module: NodeIterator -// -// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. -// and Contributors. -// -// SPDX-License-Identifier: BSL-1.0 -// - - -#include "Poco/DOM/NodeIterator.h" -#include "Poco/DOM/AbstractNode.h" -#include "Poco/DOM/NodeFilter.h" -#include "Poco/DOM/DOMException.h" - - -namespace Poco { -namespace XML { - - -NodeIterator::NodeIterator(Node* root, unsigned long whatToShow, NodeFilter* pFilter): - _pRoot(root), - _whatToShow(whatToShow), - _pFilter(pFilter), - _pCurrent(0) -{ -} - - -NodeIterator::NodeIterator(const NodeIterator& iterator): - _pRoot(iterator._pRoot), - _whatToShow(iterator._whatToShow), - _pFilter(iterator._pFilter), - _pCurrent(iterator._pCurrent) -{ -} - - -NodeIterator& NodeIterator::operator = (const NodeIterator& iterator) -{ - if (&iterator != this) - { - _pRoot = iterator._pRoot; - _whatToShow = iterator._whatToShow; - _pFilter = iterator._pFilter; - _pCurrent = iterator._pCurrent; - } - return *this; -} - - -NodeIterator::~NodeIterator() -{ -} - - -Node* NodeIterator::nextNode() -{ - if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR); - - if (_pCurrent) - _pCurrent = next(); - else - _pCurrent = _pRoot; - while (_pCurrent && !accept(_pCurrent)) - _pCurrent = next(); - return _pCurrent; -} - - -Node* NodeIterator::previousNode() -{ - if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR); - - if (_pCurrent) - _pCurrent = previous(); - else - _pCurrent = last(); - while (_pCurrent && !accept(_pCurrent)) - _pCurrent = previous(); - return _pCurrent; -} - - -void NodeIterator::detach() -{ - _pRoot = 0; - _pCurrent = 0; -} - - -bool NodeIterator::accept(Node* pNode) const -{ - bool accept = false; - switch (pNode->nodeType()) - { - case Node::ELEMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ELEMENT) != 0; break; - case Node::ATTRIBUTE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ATTRIBUTE) != 0; break; - case Node::TEXT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_TEXT) != 0; break; - case Node::CDATA_SECTION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_CDATA_SECTION) != 0; break; - case Node::ENTITY_REFERENCE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ENTITY_REFERENCE) != 0; break; - case Node::ENTITY_NODE: - accept = (_whatToShow & NodeFilter::SHOW_ENTITY) != 0; break; - case Node::PROCESSING_INSTRUCTION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_PROCESSING_INSTRUCTION) != 0; break; - case Node::COMMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_COMMENT) != 0; break; - case Node::DOCUMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT) != 0; break; - case Node::DOCUMENT_TYPE_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_TYPE) != 0; break; - case Node::DOCUMENT_FRAGMENT_NODE: - accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_FRAGMENT) != 0; break; - case Node::NOTATION_NODE: - accept = (_whatToShow & NodeFilter::SHOW_NOTATION) != 0; break; - } - if (accept && _pFilter) - accept = _pFilter->acceptNode(pNode) == NodeFilter::FILTER_ACCEPT; - return accept; -} - - -Node* NodeIterator::next() const -{ - Node* pNext = _pCurrent->firstChild(); - if (pNext) return pNext; - pNext = _pCurrent; - while (pNext && pNext != _pRoot) - { - Node* pSibling = pNext->nextSibling(); - if (pSibling) return pSibling; - pNext = pNext->parentNode(); - } - return 0; -} - - -Node* NodeIterator::previous() const -{ - if (_pCurrent == _pRoot) return 0; - Node* pPrev = _pCurrent->previousSibling(); - while (pPrev) - { - Node* pLastChild = pPrev->lastChild(); - if (pLastChild) - pPrev = pLastChild; - else - return pPrev; - } - return _pCurrent->parentNode(); -} - - -Node* NodeIterator::last() -{ - _pCurrent = _pRoot; - Node* pLast = 0; - while (_pCurrent) - { - pLast = _pCurrent; - _pCurrent = next(); - } - return pLast; -} - - -} } // namespace Poco::XML +// +// NodeIterator.cpp +// +// Library: XML +// Package: DOM +// Module: NodeIterator +// +// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH. +// and Contributors. +// +// SPDX-License-Identifier: BSL-1.0 +// + + +#include "Poco/DOM/NodeIterator.h" +#include "Poco/DOM/AbstractNode.h" +#include "Poco/DOM/NodeFilter.h" +#include "Poco/DOM/DOMException.h" + + +namespace Poco { +namespace XML { + + +NodeIterator::NodeIterator(Node* root, unsigned long whatToShow, NodeFilter* pFilter): + _pRoot(root), + _whatToShow(whatToShow), + _pFilter(pFilter), + _pCurrent(0) +{ +} + + +NodeIterator::NodeIterator(const NodeIterator& iterator): + _pRoot(iterator._pRoot), + _whatToShow(iterator._whatToShow), + _pFilter(iterator._pFilter), + _pCurrent(iterator._pCurrent) +{ +} + + +NodeIterator& NodeIterator::operator = (const NodeIterator& iterator) +{ + if (&iterator != this) + { + _pRoot = iterator._pRoot; + _whatToShow = iterator._whatToShow; + _pFilter = iterator._pFilter; + _pCurrent = iterator._pCurrent; + } + return *this; +} + + +NodeIterator::~NodeIterator() +{ +} + + +Node* NodeIterator::nextNode() +{ + if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR); + + if (_pCurrent) + _pCurrent = next(); + else + _pCurrent = _pRoot; + while (_pCurrent && !accept(_pCurrent)) + _pCurrent = next(); + return _pCurrent; +} + + +Node* NodeIterator::previousNode() +{ + if (!_pRoot) throw DOMException(DOMException::INVALID_STATE_ERR); + + if (_pCurrent) + _pCurrent = previous(); + else + _pCurrent = last(); + while (_pCurrent && !accept(_pCurrent)) + _pCurrent = previous(); + return _pCurrent; +} + + +void NodeIterator::detach() +{ + _pRoot = 0; + _pCurrent = 0; +} + + +bool NodeIterator::accept(Node* pNode) const +{ + bool accept = false; + switch (pNode->nodeType()) + { + case Node::ELEMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ELEMENT) != 0; break; + case Node::ATTRIBUTE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ATTRIBUTE) != 0; break; + case Node::TEXT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_TEXT) != 0; break; + case Node::CDATA_SECTION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_CDATA_SECTION) != 0; break; + case Node::ENTITY_REFERENCE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ENTITY_REFERENCE) != 0; break; + case Node::ENTITY_NODE: + accept = (_whatToShow & NodeFilter::SHOW_ENTITY) != 0; break; + case Node::PROCESSING_INSTRUCTION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_PROCESSING_INSTRUCTION) != 0; break; + case Node::COMMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_COMMENT) != 0; break; + case Node::DOCUMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT) != 0; break; + case Node::DOCUMENT_TYPE_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_TYPE) != 0; break; + case Node::DOCUMENT_FRAGMENT_NODE: + accept = (_whatToShow & NodeFilter::SHOW_DOCUMENT_FRAGMENT) != 0; break; + case Node::NOTATION_NODE: + accept = (_whatToShow & NodeFilter::SHOW_NOTATION) != 0; break; + } + if (accept && _pFilter) + accept = _pFilter->acceptNode(pNode) == NodeFilter::FILTER_ACCEPT; + return accept; +} + + +Node* NodeIterator::next() const +{ + Node* pNext = _pCurrent->firstChild(); + if (pNext) return pNext; + pNext = _pCurrent; + while (pNext && pNext != _pRoot) + { + Node* pSibling = pNext->nextSibling(); + if (pSibling) return pSibling; + pNext = pNext->parentNode(); + } + return 0; +} + + +Node* NodeIterator::previous() const +{ + if (_pCurrent == _pRoot) return 0; + Node* pPrev = _pCurrent->previousSibling(); + while (pPrev) + { + Node* pLastChild = pPrev->lastChild(); + if (pLastChild) + pPrev = pLastChild; + else + return pPrev; + } + return _pCurrent->parentNode(); +} + + +Node* NodeIterator::last() +{ + _pCurrent = _pRoot; + Node* pLast = 0; + while (_pCurrent) + { + pLast = _pCurrent; + _pCurrent = next(); + } + return pLast; +} + + +} } // namespace Poco::XML |