/*
Add a selector that matches source keys that start with the
specified prefix.

@param {string} prefix
@param {function} [selector] The selector for the specified prefix.
@return {function} The selector for the specified prefix.
508043
function addSelector(prefix, selector) {
        if (selector !== undefined) {
            selectors[prefix] = selector;
        }
        return selectors[prefix];
    }
491944
function(prefix, string) {
    return string.substring(0, prefix.length) == prefix ?
        string.substring(prefix.length) :
        '';
  }
934215
function appendElementSelector (element, selector) {
  const processor = selectorParser((selectors) => {
    let combinatorNode = null

    /**
     * looping breaks if we insert dynamically
     */
    selectors.each((selector) => {
      const elementNode = selectorParser.tag({ value: element.tag })
      selector.walk((node) => {
        if (node.type === 'combinator') { combinatorNode = node }
      })

      if (combinatorNode) {
        selector.insertAfter(combinatorNode, elementNode)
      } else {
        selector.prepend(elementNode)
      }
    })
  })

  return processor.process(selector).result
}
1354821
function negationSelector(selectorContext) {
    // If no properties currently selected, select them all first.
    if (isEmpty(selectorContext.sourceKeys)) {
        extendSourceKeys(selectorContext.sourceKeys, selectorContext.source);
    }
    // Then remove the negated property.
    if (selectorContext.sourceKeys[selectorContext.sourceKey] !== undefined) {
        delete selectorContext.sourceKeys[selectorContext.sourceKey];

    } else {
        // Throw error if negated property not found.
        errorManager.propertyNotFound(selectorContext.sourceKey, selectorContext.source);
    }
}
988572
public static <T extends NamedElement> ElementMatcher.Junction<T> nameStartsWith(String prefix) {
        return new NameMatcher<T>(new StringMatcher(prefix, StringMatcher.Mode.STARTS_WITH));
    }
68245
public static List<String> getKeys(String prefix) {
        List<String> res = new ArrayList<>();
        for(String key: props.keySet()){
            if(key.startsWith(prefix)){
                res.add(key);
            }
        }
        return res;
    }
1325129
function prefixMatchLength(name, prefix) {
  var prefixParts = prefix.split('/');
  var nameParts = name.split('/');
  if (prefixParts.length > nameParts.length)
    return 0;
  for (var i = 0; i < prefixParts.length; i++) {
    if (nameParts[i] != prefixParts[i])
      return 0;
  }
  return prefixParts.length;
}
600407
function overrideSelector(selectorContext) {
    selectorContext.overrideKeys[selectorContext.sourceKey] = true;
    selectorContext.sourceKeys[selectorContext.sourceKey] = selectorContext.targetKey;
}
1276576
public static final Function<String, Boolean> startsWith(final String prefix, final int offset) {
        return new StartsWith(prefix, offset);
    }
574752
public static Matcher<MethodTree> methodNameStartsWith(final String prefix) {
    return new Matcher<MethodTree>() {
      @Override
      public boolean matches(MethodTree methodTree, VisitorState state) {
        return methodTree.getName().toString().startsWith(prefix);
      }
    };
  }
782792
def get_source(self, key, name_spaces=None, default_prefix=''):
        
        source = self.source or key
        prefix = default_prefix
        if name_spaces and self.name_space and self.name_space in name_spaces:
            prefix = ''.join([name_spaces[self.name_space], ':'])
        return ''.join([prefix, source])
634770
def __prefix_key(self, key):
        
        # If there isn't a prefix don't bother
        if self.prefix is None:
            return key

        # Don't prefix key if it already has it
        if key.startswith(self.prefix + "-"):
            return key

        return "{0}-{1}".format(self.prefix, key)
1242620
function selector() {
        whitespace();

        while (css[0] === '}') {
            error('extra closing bracket');
        }

        const m = match(/^(("(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^{])+)/);

        if (m) {
            return m[0]
                .trim() // remove all comments from selectors
                .replace(/\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*\/+/g, '')
                .replace(/"(?:\\"|[^"])*"|'(?:\\'|[^'])*'/g, function(m) {
                    return m.replace(/,/g, '\u200C');
                })
                .split(/\s*(?![^(]*\)),\s*/)
                .map(function(s) {
                    return s.replace(/\u200C/g, ',');
                });
        }
    }
736503
function(selector) {
            selector = selector || '';
            selector = Selector._replaceShorthand(Y.Lang.trim(selector)); 
            var token = Selector._getToken(),     // one token per simple selector (left selector holds combinator)
                query = selector, // original query for debug report
                tokens = [],    // array of tokens
                found = false,  // whether or not any matches were found this pass
                match,         // the regex match
                test,
                i, parser;

            /*
                Search for selector patterns, store, and strip them from the selector string
                until no patterns match (invalid selector) or we run out of chars.

                Multiple attributes and pseudos are allowed, in any order.
                for example:
                    'form:first-child[type=button]:not(button)[lang|=en]'
            */
            outer:
            do {
                found = false; // reset after full pass
                for (i = 0; (parser = Selector._parsers[i++]);) {
                    if ( (match = parser.re.exec(selector)) ) { // note assignment
                        if (parser.name !== COMBINATOR ) {
                            token.selector = selector;
                        }
                        selector = selector.replace(match[0], ''); // strip current match from selector
                        if (!selector.length) {
                            token.last = true;
                        }

                        if (Selector._attrFilters[match[1]]) { // convert class to className, etc.
                            match[1] = Selector._attrFilters[match[1]];
                        }

                        test = parser.fn(match, token);
                        if (test === false) { // selector not supported
                            found = false;
                            break outer;
                        } else if (test) {
                            token.tests.push(test);
                        }

                        if (!selector.length || parser.name === COMBINATOR) {
                            tokens.push(token);
                            token = Selector._getToken(token);
                            if (parser.name === COMBINATOR) {
                                token.combinator = Y.Selector.combinators[match[1]];
                            }
                        }
                        found = true;
                    }
                }
            } while (found && selector.length);

            if (!found || selector.length) { // not fully parsed
                tokens = [];
            }
            return tokens;
        }
774378
function(node, source, params) {
			var proposals = [];
			var prefix = params.prefix ? params.prefix : "";
			// we need to check if we need to rebuild the prefix for completion that contains a '-'
			var index = params.offset - prefix.length - 1;
			if (index > 0 && index < source.length) {
				var precedingChar = source.charAt(index);
				if (precedingChar === '=' && prefix.length === 0 && (index - 1) > 0) {
					precedingChar = source.charAt(index - 1);
					if (/[A-Za-z0-9_]/.test(precedingChar)) {
						if (index + 1 >= source.length || 
								(source.charAt(index + 1) !== '\"' && source.charAt(index + 1) !== "'")) {
							proposals.push(this.makeComputedProposal("\"\"",  Messages['addQuotesToAttributes'], " - \"\"", null, prefix)); //$NON-NLS-1$ //$NON-NLS-2$
						}
					}
				}
			}
			var vals = Attributes.getValuesForAttribute(node);
			if(Array.isArray(vals)) {
				proposals = proposals.concat(this.addProposals(node, vals, params));
			}
			return proposals;	
		}
283057
function prefix(value, prefix, ignored = []) {
	if (prefix === false) {
		return value;
	}

	if (ignored.includes(prefix)) {
		return toDashCase(value);
	}

	return prefix + '-' + toDashCase(value);
}
315045
function createSelectorsManager() {
    var selectors = {};

    return {
        addSelector: addSelector,
        executeSelector: executeSelector
    };

    /*
     * Add a selector that matches source keys that start with the
     * specified prefix.
     *
     * @param {string} prefix
     * @param {function} [selector] The selector for the specified prefix.
     * @return {function} The selector for the specified prefix.
     */
    function addSelector(prefix, selector) {
        if (selector !== undefined) {
            selectors[prefix] = selector;
        }
        return selectors[prefix];
    }

    /*
     * Checks whether the source key matches one of the existing selectors.
     * If it does, the selector's handler is invoked on the source key.
     *
     * @param {object} source The source object.
     * @param {string} sourceKey The source object key.
     * @param {string} targetKey The target object key.
     * @param {object} sourceKeys The keys of the source properties to merge.
     * @param {object} overrideKeys
     *    The keys of the source properties to not report an error if the
     *    property already exists in the target object.
     */
    function executeSelector(source, sourceKey, targetKey,
        sourceKeys, overrideKeys) {

        for (var prefix in selectors) {
            // sourceKey starts with selector's prefix
            if (sourceKey.indexOf(prefix) === 0) {

                // Remove prefix from source key.
                sourceKey = sourceKey.substring(prefix.length);

                // Execute the selector's handler.
                selectors[prefix]({
                    source: source,
                    sourceKey: sourceKey,
                    targetKey: targetKey ? targetKey : sourceKey,
                    sourceKeys: sourceKeys,
                    overrideKeys: overrideKeys
                });

                return true;
            }
        }
        return false;
    }
}