This source file includes following definitions.
- isRootDomNode
- stringValue
- isValidContextNode
#include "config.h"
#include "core/xml/XPathUtil.h"
#include "core/dom/ContainerNode.h"
#include "core/dom/NodeTraversal.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
namespace XPath {
bool isRootDomNode(Node* node)
{
return node && !node->parentNode();
}
String stringValue(Node* node)
{
switch (node->nodeType()) {
case Node::ATTRIBUTE_NODE:
case Node::PROCESSING_INSTRUCTION_NODE:
case Node::COMMENT_NODE:
case Node::TEXT_NODE:
case Node::CDATA_SECTION_NODE:
return node->nodeValue();
default:
if (isRootDomNode(node) || node->nodeType() == Node::ELEMENT_NODE) {
StringBuilder result;
result.reserveCapacity(1024);
for (Node* n = node->firstChild(); n; n = NodeTraversal::next(*n, node)) {
if (n->isTextNode()) {
const String& nodeValue = n->nodeValue();
result.append(nodeValue);
}
}
return result.toString();
}
}
return String();
}
bool isValidContextNode(Node* node)
{
if (!node)
return false;
switch (node->nodeType()) {
case Node::ATTRIBUTE_NODE:
case Node::CDATA_SECTION_NODE:
case Node::COMMENT_NODE:
case Node::DOCUMENT_NODE:
case Node::ELEMENT_NODE:
case Node::PROCESSING_INSTRUCTION_NODE:
return true;
case Node::DOCUMENT_FRAGMENT_NODE:
case Node::DOCUMENT_TYPE_NODE:
return false;
case Node::TEXT_NODE:
return !(node->parentNode() && node->parentNode()->isAttributeNode());
}
ASSERT_NOT_REACHED();
return false;
}
}
}