A utility function to match an Ivy node static data against a simple CSS selector

@param node static data to match
@param selector
@returns true if node matches the selector.
195636
function isNodeMatchingSelector(tNode, selector) {
    ngDevMode && assertDefined(selector[0], 'Selector should have a tag name');
    var mode = 4 /* ELEMENT */;
    var nodeAttrs = tNode.attrs;
    var selectOnlyMarkerIdx = nodeAttrs ? nodeAttrs.indexOf(1 /* SelectOnly */) : -1;
    // When processing ":not" selectors, we skip to the next ":not" if the
    // current one doesn't match
    var skipToNextSelector = false;
    for (var i = 0; i < selector.length; i++) {
        var current = selector[i];
        if (typeof current === 'number') {
            // If we finish processing a :not selector and it hasn't failed, return false
            if (!skipToNextSelector && !isPositive(mode) && !isPositive(current)) {
                return false;
            }
            // If we are skipping to the next :not() and this mode flag is positive,
            // it's a part of the current :not() selector, and we should keep skipping
            if (skipToNextSelector && isPositive(current))
                continue;
            skipToNextSelector = false;
            mode = current | (mode & 1 /* NOT */);
            continue;
        }
        if (skipToNextSelector)
            continue;
        if (mode & 4 /* ELEMENT */) {
            mode = 2 /* ATTRIBUTE */ | mode & 1 /* NOT */;
            if (current !== '' && current !== tNode.tagName) {
                if (isPositive(mode))
                    return false;
                skipToNextSelector = true;
            }
        }
        else {
            var attrName = mode & 8 /* CLASS */ ? 'class' : current;
            var attrIndexInNode = findAttrIndexInNode(attrName, nodeAttrs);
            if (attrIndexInNode === -1) {
                if (isPositive(mode))
                    return false;
                skipToNextSelector = true;
                continue;
            }
            var selectorAttrValue = mode & 8 /* CLASS */ ? current : selector[++i];
            if (selectorAttrValue !== '') {
                var nodeAttrValue = void 0;
                var maybeAttrName = nodeAttrs[attrIndexInNode];
                if (selectOnlyMarkerIdx > -1 && attrIndexInNode > selectOnlyMarkerIdx) {
                    nodeAttrValue = '';
                }
                else {
                    ngDevMode && assertNotEqual(maybeAttrName, 0 /* NamespaceURI */, 'We do not match directives on namespaced attributes');
                    nodeAttrValue = nodeAttrs[attrIndexInNode + 1];
                }
                if (mode & 8 /* CLASS */ &&
                    !isCssClassMatching(nodeAttrValue, selectorAttrValue) ||
                    mode & 2 /* ATTRIBUTE */ && selectorAttrValue !== nodeAttrValue) {
                    if (isPositive(mode))
                        return false;
                    skipToNextSelector = true;
                }
            }
        }
    }
    return isPositive(mode) || skipToNextSelector;
}
104957
public static boolean matches(Pattern patternMatcher, Object... elements)
    {
        if (patternMatcher == null) {
            return true;
        }

        for (Object element : elements) {
            if (matches(patternMatcher, element)) {
                return true;
            }
        }

        return false;
    }
131783
public static Node selectNode(Node dom, String xpath) {
        return selector.selectNode(dom, xpath);
    }
1072476
public ResultMatcher matches(final Matcher<?> matcher) {
        return new AbstractResultMatcher(path, configuration) {
            public void doMatch(Object actual) {
                isPresent(actual);
                Node node = getNode(actual);
                assertThat("Node \"" + path + "\" does not match.", node.getValue(), (Matcher<? super Object>) matcher);
            }
        };

    }
987472
public static final String css2xpath(String css, boolean isRoot) {
        Scanner scanner = new Scanner(css);
        List<List<Selector>> selectors = scanner.scan();

        StringBuilder sb = new StringBuilder();
        String selectorSeparator = "";
        for (List<Selector> selector : selectors) {
            sb.append(selectorSeparator);

            // [#95] Append a dot if we should match only descendants of a
            // non-root element
            if (!isRoot) {
                sb.append(".");
            }

            for (Selector s : selector) {
                switch (s.getCombinator()) {
                    case CHILD:
                        sb.append("/");
                        break;
                    case DESCENDANT:
                        sb.append("//");
                        break;
                    case ADJACENT_SIBLING:

                        // TODO: Implement this
                        sb.append("?????");
                        break;
                    case GENERAL_SIBLING:

                        // TODO: Implement this
                        sb.append("?????");
                        break;
                }

                sb.append(s.getTagName());

                if (s.hasSpecifiers()) {
                    for (Specifier specifier : s.getSpecifiers()) {
                        switch (specifier.getType()) {
                            case ATTRIBUTE: {
                                AttributeSpecifier a = ((AttributeSpecifier) specifier);

                                sb.append("[");

                                if (a.getMatch() == null) {
                                    sb.append("@");
                                    sb.append(a.getName());
                                }
                                else {
                                    switch (a.getMatch()) {
                                        case EXACT: {
                                            sb.append("@");
                                            sb.append(a.getName());
                                            sb.append("='");
                                            sb.append(a.getValue().replace("'", "\\'"));
                                            sb.append("'");
                                            break;
                                        }

                                        case CONTAINS: {
                                            sb.append("contains(@");
                                            sb.append(a.getName());
                                            sb.append(", '");
                                            sb.append(a.getValue().replace("'", "\\'"));
                                            sb.append("')");
                                            break;
                                        }

                                        case HYPHEN: {
                                            sb.append("@");
                                            sb.append(a.getName());
                                            sb.append("='");
                                            sb.append(a.getValue().replace("'", "\\'"));
                                            sb.append("' or starts-with(@");
                                            sb.append(a.getName());
                                            sb.append(", '");
                                            sb.append(a.getValue().replace("'", "\\'"));
                                            sb.append("-')");
                                            break;
                                        }

                                        case PREFIX: {
                                            sb.append("starts-with(@");
                                            sb.append(a.getName());
                                            sb.append(", '");
                                            sb.append(a.getValue().replace("'", "\\'"));
                                            sb.append("')");
                                            break;
                                        }

                                        case SUFFIX: {
                                            endsWith(sb, a.getName(), a.getValue());
                                            break;
                                        }

                                        case LIST: {
                                            sb.append("@");
                                            sb.append(a.getName());
                                            sb.append("='");
                                            sb.append(a.getValue().replace("'", "\\'"));
                                            sb.append("' or starts-with(@");
                                            sb.append(a.getName());
                                            sb.append(", '");
                                            sb.append(a.getValue().replace("'", "\\'"));
                                            sb.append(" ')");
                                            sb.append(" or ");
                                            endsWith(sb, a.getName(), " " + a.getValue());
                                            sb.append(" or contains(@");
                                            sb.append(a.getName());
                                            sb.append(", ' ");
                                            sb.append(a.getValue().replace("'", "\\'"));
                                            sb.append(" ')");
                                            break;
                                        }
                                    }
                                }

                                sb.append("]");
                                break;
                            }

                            case NEGATION: {
                                sb.append("[not(");

                                // TODO: implement this..??

                                sb.append(")]");
                                break;
                            }

                            case PSEUDO: {
                                if (specifier instanceof PseudoClassSpecifier) {
                                    PseudoClassSpecifier p = ((PseudoClassSpecifier) specifier);
                                    String value = p.getValue();

                                    if ("empty".equals(value))
                                        sb.append("[not(*|@*|node())]");
                                    else if ("first-child".equals(value))
                                        sb.append("[not(preceding-sibling::*)]");
                                    else if ("last-child".equals(value))
                                        sb.append("[not(following-sibling::*)]");
                                    else if ("only-child".equals(value))
                                        sb.append("[not(preceding-sibling::*) and not(following-sibling::*)]");
                                    else if ("root".equals(value))
                                        sb.append("[not(parent::*)]");
                                }
                                else if (specifier instanceof PseudoNthSpecifier) {
                                    PseudoNthSpecifier p = ((PseudoNthSpecifier) specifier);
                                    String value = p.getValue();

                                    if ("nth-child".equals(value)) {
                                        sb.append("[count(preceding-sibling::*) = ");
                                        sb.append(p.getArgument());
                                        sb.append(" - 1]");
                                    }

                                    // TODO: Implement this...?
                                }
                                break;
                            }
                        }
                    }
                }
            }

            selectorSeparator = " | ";
        }

        return sb.toString();
    }
1043952
function matches(elem, selector) {
  // We'll use querySelectorAll to find all element matching the selector,
  // then check if the given element is included in that list.
  // Executing the query on the parentNode reduces the resulting nodeList,
  // document doesn't have a parentNode, though.
  var nodeList = ( elem.parentNode || document ).querySelectorAll( selector ) || [],
      i = nodeList.length;

  // loop on the nodeList
  while ( i-- ) {
    if ( nodeList[i] == elem ) { return true; }
  }
  return false;
}
785105
function matchesSelector(element, selector) {
    var matchesImpl = element.matches || element.webkitMatchesSelector || element.mozMatchesSelector || element.msMatchesSelector || function (s) {
      return matchesSelector_SLOW(element, s);
    };
    return matchesImpl.call(element, selector);
  }
878139
public static boolean nodeMatches(final Node nd, final QName tag) {
    if (tag == null) {
      return false;
    }

    String ns = nd.getNamespaceURI();

    if (ns == null) {
      /* It appears a node can have a NULL namespace but a QName has a zero length
       */
      if ((tag.getNamespaceURI() != null) && (!"".equals(tag.getNamespaceURI()))) {
        return false;
      }
    } else if (!ns.equals(tag.getNamespaceURI())) {
      return false;
    }

    String ln = nd.getLocalName();

    if (ln == null) {
      if (tag.getLocalPart() != null) {
        return false;
      }
    } else if (!ln.equals(tag.getLocalPart())) {
      return false;
    }

    return true;
  }
189541
public void setSelector(String selector)
  {
    if (tc.isEntryEnabled())
      SibTr.entry(tc, "setSelector", selector);

    this.selector = selector;

    if (tc.isEntryEnabled())
      SibTr.exit(tc, "setSelector");
  }
1093135
public boolean appliesTo(Node node) {
        Label l = Jenkins.getInstance().getLabel(label);
        return l == null || l.contains(node);
    }
424830
public boolean matches(final Node node) throws IllegalArgumentException {
        // Precondition checks
        if (node == null) {
            throw new IllegalArgumentException("node must be specified");
        }

        if (!name.equals(node.getName())) {
            return false;
        }

        if ((text != null && node.getText() == null) || (text != null && !text.trim().equals(node.getText().trim()))) {
            return false;
        }

        if (attributes != null) {
            for (final Map.Entry<String, String> attribute : attributes.entrySet()) {
                final String attrValue = attribute.getValue();
                final String attrName = attribute.getKey();

                if (!attrValue.equals(node.getAttribute(attrName))) {
                    return false;
                }
            }
        }

        return true;
    }
577587
function _match(elm, selector)
    {
        if (!selector) {
            return true;
        }

        var tag = selector.uTag,
            id = selector.id,
            classes = selector.classes;

        return (elm.nodeType === 1) &&
        !(tag && tag !== elm.tagName) &&
        !(id && id !== elm.id) &&
        !(classes && !_hasClasses(elm, classes));
    }
847060
function ( selector ) {
            var node = this.element().nextSibling;
            if ( !node ) return;
    
            //comment, text
            if ( node.nodeType == 8 || node.nodeType == 3 && !$B.string.trim(node.data) ) {
                return $B( node ).next( selector );
            } else {
                if ( typeof selector === 'string' ) node = $B.selector.match( node, selector )? node : undefined;
                return node;
            }
        }
312148
def match(self, node, results=None):
        """"""
        if not isinstance(node, Leaf):
            return False
        return BasePattern.match(self, node, results)
718419
function match (el, selector) {
  if (!el || el.nodeType !== 1) return false
  if (vendor) return vendor.call(el, selector)
  var nodes = all(selector, el.parentNode)
  for (var i = 0; i < nodes.length; ++i) {
    if (nodes[i] === el) return true
  }
  return false
}
233712
static <K extends Comparable<K>> void checkNode(Node<K> node) {
        node.checkNode(null, null);
    }
923691
function querySelector(selector) {
    init();
    if (!selector) {
      return tokens;
    }
    var match = selector.match(
      /^\s*([\w_-]*)((\s*\[[\w_-]+\s*=\s*("([^\\"]*(\\.)*)*"|'([^\\']*(\\.)*)*'|[^\[\]]*)\])*)\s*(\*?)$/
    );
    if (!match) {
      console.warn(colors.blue('Invalid selector expressions %j.'), selector);
      return;
    }
    var tag = match[1];
    var attributes = [];
    var all = match[9] === '*';
    match[2].replace(/\s*\[([\w_-]+)\s*=\s*("([^\\"]*(\\.)*)*"|'([^\\']*(\\.)*)*'|[^\[\]]*)\]/g,
      function (match, name, value) {
        if (/^['"]/.test(value)) {
          /*jslint evil: true */
          value = new Function('return (' + value + ');')();
        }
        attributes.push({
          name: name,
          value: value
        });
      }
    );
    function check(node) {
      if (!node || !node.attrs) {
        return;
      }
      var flag;
      if (!tag || node.tag === tag) {
        flag = true;
        attributes.every(function (item) {
          if (item.value !== node.attrs[item.name]) {
            flag = false;
          }
          return flag;
        });
      }
      return flag;
    }
    var items;
    function scan(node) {
      if (check(node)) {
        if (items) {
          items.push(node);
        }
        return node;
      }
      var result;
      if (node.nodes) {
        node.nodes.every(function (item) {
          result = scan(item);
          return items || !result;
        });
      }
      return result;
    }
    if (all) {
      items = [];
      scan(tokens);
      return items;
    }
    else {
      return scan(tokens);
    }
  }