tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

txNamedAttributeStep.cpp (1673B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #include "nsAtom.h"
      7 #include "txExpr.h"
      8 #include "txIXPathContext.h"
      9 #include "txNodeSet.h"
     10 #include "txXPathTreeWalker.h"
     11 
     12 txNamedAttributeStep::txNamedAttributeStep(int32_t aNsID, nsAtom* aPrefix,
     13                                           nsAtom* aLocalName)
     14    : mNamespace(aNsID), mPrefix(aPrefix), mLocalName(aLocalName) {}
     15 
     16 nsresult txNamedAttributeStep::evaluate(txIEvalContext* aContext,
     17                                        txAExprResult** aResult) {
     18  *aResult = nullptr;
     19 
     20  RefPtr<txNodeSet> nodes;
     21  nsresult rv = aContext->recycler()->getNodeSet(getter_AddRefs(nodes));
     22  NS_ENSURE_SUCCESS(rv, rv);
     23 
     24  txXPathTreeWalker walker(aContext->getContextNode());
     25  if (walker.moveToNamedAttribute(mLocalName, mNamespace)) {
     26    rv = nodes->append(walker.getCurrentPosition());
     27    NS_ENSURE_SUCCESS(rv, rv);
     28  }
     29  NS_ADDREF(*aResult = nodes);
     30 
     31  return NS_OK;
     32 }
     33 
     34 TX_IMPL_EXPR_STUBS_0(txNamedAttributeStep, NODESET_RESULT)
     35 
     36 bool txNamedAttributeStep::isSensitiveTo(ContextSensitivity aContext) {
     37  return !!(aContext & NODE_CONTEXT);
     38 }
     39 
     40 #ifdef TX_TO_STRING
     41 void txNamedAttributeStep::toString(nsAString& aDest) {
     42  aDest.Append(char16_t('@'));
     43  if (mPrefix) {
     44    nsAutoString prefix;
     45    mPrefix->ToString(prefix);
     46    aDest.Append(prefix);
     47    aDest.Append(char16_t(':'));
     48  }
     49  nsAutoString localName;
     50  mLocalName->ToString(localName);
     51  aDest.Append(localName);
     52 }
     53 #endif