/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// If the value attribute exists then use that if (aValueExpr) {
RefPtr<txAExprResult> result;
rv = aValueExpr->evaluate(aContext, getter_AddRefs(result));
NS_ENSURE_SUCCESS(rv, rv);
double value = result->numberValue();
if (std::isinf(value) || std::isnan(value) || value < 0.5) {
txDouble::toString(value, aValueString); return NS_OK;
}
if (!aCountPattern) {
txNodeTest* nodeTest;
uint16_t nodeType = txXPathNodeUtils::getNodeType(currNode); switch (nodeType) { case txXPathNodeType::ELEMENT_NODE: {
RefPtr<nsAtom> localName = txXPathNodeUtils::getLocalName(currNode);
int32_t namespaceID = txXPathNodeUtils::getNamespaceID(currNode);
nodeTest = new txNameTest(0, localName, namespaceID,
txXPathNodeType::ELEMENT_NODE); break;
} case txXPathNodeType::TEXT_NODE: case txXPathNodeType::CDATA_SECTION_NODE: {
nodeTest = new txNodeTypeTest(txNodeTypeTest::TEXT_TYPE); break;
} case txXPathNodeType::PROCESSING_INSTRUCTION_NODE: {
txNodeTypeTest* typeTest;
typeTest = new txNodeTypeTest(txNodeTypeTest::PI_TYPE);
nsAutoString nodeName;
txXPathNodeUtils::getNodeName(currNode, nodeName);
typeTest->setNodeName(nodeName);
nodeTest = typeTest; break;
} case txXPathNodeType::COMMENT_NODE: {
nodeTest = new txNodeTypeTest(txNodeTypeTest::COMMENT_TYPE); break;
} case txXPathNodeType::DOCUMENT_NODE: case txXPathNodeType::ATTRIBUTE_NODE: default: { // this won't match anything as we walk up the tree // but it's what the spec says to do
nodeTest = new txNameTest(0, nsGkAtoms::_asterisk, 0, nodeType); break;
}
}
MOZ_ASSERT(nodeTest);
newCountPattern = MakeUnique<txStepPattern>(nodeTest, false);
countPattern = newCountPattern.get();
}
// Generate list of values depending on the value of the level-attribute
// level = "single" if (aLevel == eLevelSingle) {
txXPathTreeWalker walker(currNode); do { if (aFromPattern && !walker.isOnNode(currNode)) { bool matched;
rv = aFromPattern->matches(walker.getCurrentPosition(), aContext,
matched);
NS_ENSURE_SUCCESS(rv, rv);
// Spec says to only match ancestors that are decendants of the // ancestor that matches the from-pattern, so keep going to make // sure that there is an ancestor that does. if (aFromPattern && aValues.getLength()) { bool hasParent; while ((hasParent = walker.moveToParent())) { bool matched;
rv = aFromPattern->matches(walker.getCurrentPosition(), aContext,
matched);
NS_ENSURE_SUCCESS(rv, rv);
if (matched) { break;
}
}
if (!hasParent) {
aValues.clear();
}
}
} // level = "multiple" elseif (aLevel == eLevelMultiple) { // find all ancestor-or-selfs that matches count until...
txXPathTreeWalker walker(currNode); bool matchedFrom = false; do { if (aFromPattern && !walker.isOnNode(currNode)) {
rv = aFromPattern->matches(walker.getCurrentPosition(), aContext,
matchedFrom);
NS_ENSURE_SUCCESS(rv, rv);
if (matchedFrom) { //... we find one that matches from break;
}
}
aValues.add(NS_INT32_TO_PTR(count));
}
} while (walker.moveToParent());
// Spec says to only match ancestors that are decendants of the // ancestor that matches the from-pattern, so if none did then // we shouldn't search anything if (aFromPattern && !matchedFrom) {
aValues.clear();
}
} // level = "any" elseif (aLevel == eLevelAny) {
int32_t value = 0; bool matchedFrom = false;
txXPathTreeWalker walker(currNode); do { if (aFromPattern && !walker.isOnNode(currNode)) {
rv = aFromPattern->matches(walker.getCurrentPosition(), aContext,
matchedFrom);
NS_ENSURE_SUCCESS(rv, rv);
// Spec says to only count nodes that follows the first node that // matches the from pattern. So so if none did then we shouldn't // count any if (aFromPattern && !matchedFrom) {
value = 0;
}
if (value) {
aValues.add(NS_INT32_TO_PTR(value));
}
}
// start with header while (formatPos < formatLen &&
!isAlphaNumeric(ch = format.CharAt(formatPos))) {
aHead.Append(ch);
++formatPos;
}
// If there are no formatting tokens we need to create a default one. if (formatPos == formatLen) {
txFormattedCounter* defaultCounter;
rv = txFormattedCounter::getCounterFor(u"1"_ns, groupSize, groupSeparator,
defaultCounter);
NS_ENSURE_SUCCESS(rv, rv);
while (formatPos < formatLen) {
nsAutoString sepToken; // parse separator token if (!aCounters.getLength()) { // Set the first counters separator to default value so that if // there is only one formatting token and we're formatting a // value-list longer then one we use the default separator. This // won't be used when formatting the first value anyway.
sepToken.Assign('.');
} else { while (formatPos < formatLen &&
!isAlphaNumeric(ch = format.CharAt(formatPos))) {
sepToken.Append(ch);
++formatPos;
}
}
// if we're at the end of the string then the previous token was the tail if (formatPos == formatLen) {
aTail = sepToken; return NS_OK;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.3Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.