當前位置: 首頁>>代碼示例>>Java>>正文


Java XTokenQueue類代碼示例

本文整理匯總了Java中us.codecraft.xsoup.XTokenQueue的典型用法代碼示例。如果您正苦於以下問題:Java XTokenQueue類的具體用法?Java XTokenQueue怎麽用?Java XTokenQueue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XTokenQueue類屬於us.codecraft.xsoup包,在下文中一共展示了XTokenQueue類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: byFunction

import us.codecraft.xsoup.XTokenQueue; //導入依賴的package包/類
private Evaluator byFunction(XTokenQueue predicatesQueue) {
    for (Map.Entry<String, FunctionEvaluator> entry : FUNCTION_MAPPING.entrySet()) {
        if (predicatesQueue.matchChomp(entry.getKey())) {
            String paramString = predicatesQueue.chompBalanced('(', ')');
            List<String> params = XTokenQueue.trimQuotes(XTokenQueue.parseFuncionParams(paramString));

            if (params.get(0).startsWith("@")) {
                params.set(0, params.get(0).substring(1));
                return entry.getValue().call(params.toArray(new String[0]));
            } else {
                return null;
            }
        }
    }

    throw new Selector.SelectorParseException("Could not parse query '%s': unexpected token at '%s'", query, predicatesQueue.remainder());
}
 
開發者ID:code4craft,項目名稱:xsoup,代碼行數:18,代碼來源:XPathParser.java

示例2: functionRegex

import us.codecraft.xsoup.XTokenQueue; //導入依賴的package包/類
private void functionRegex(String remainder) {
    Validate.isTrue(remainder.endsWith(")"), "Unclosed bracket for function! " + remainder);
    List<String> params = XTokenQueue.trimQuotes(XTokenQueue.parseFuncionParams(remainder.substring("regex(".length(), remainder.length() - 1)));
    if (params.size() == 1) {
        elementOperator = new ElementOperator.Regex(params.get(0));
    } else if (params.size() == 2) {
        if (params.get(0).startsWith("@")) {
            elementOperator = new ElementOperator.Regex(params.get(1), params.get(0).substring(1));
        } else {
            elementOperator = new ElementOperator.Regex(params.get(0), null, Integer.parseInt(params.get(1)));
        }
    } else if (params.size() == 3) {
        elementOperator = new ElementOperator.Regex(params.get(1), params.get(0).substring(1), Integer.parseInt(params.get(2)));
    } else {
        throw new Selector.SelectorParseException("Unknown usage for regex()" + remainder);
    }
}
 
開發者ID:code4craft,項目名稱:xsoup,代碼行數:18,代碼來源:XPathParser.java

示例3: removePadding

import us.codecraft.xsoup.XTokenQueue; //導入依賴的package包/類
/**
 * remove padding for JSONP
 * @param padding padding
 * @return json after padding removed
 */
public Json removePadding(String padding) {
    String text = getFirstSourceText();
    XTokenQueue tokenQueue = new XTokenQueue(text);
    tokenQueue.consumeWhitespace();
    tokenQueue.consume(padding);
    tokenQueue.consumeWhitespace();
    String chompBalanced = tokenQueue.chompBalancedNotInQuotes('(', ')');
    return new Json(chompBalanced);
}
 
開發者ID:fengzhizi715,項目名稱:NetDiscovery,代碼行數:15,代碼來源:Json.java

示例4: consumePredicates

import us.codecraft.xsoup.XTokenQueue; //導入依賴的package包/類
private Evaluator consumePredicates(String queue) {
    XTokenQueue predicatesQueue = new XTokenQueue(queue);
    EvaluatorStack evaluatorStack = new EvaluatorStack();
    Operation currentOperation = null;
    predicatesQueue.consumeWhitespace();
    while (!predicatesQueue.isEmpty()) {
        if (predicatesQueue.matchChomp("and")) {
            currentOperation = Operation.AND;
        } else if (predicatesQueue.matchChomp("or")) {
            currentOperation = Operation.OR;
        } else {
            if (currentOperation == null && evaluatorStack.size() > 0) {
                throw new IllegalArgumentException(String.format("Need AND/OR between two predicate! %s", predicatesQueue.remainder()));
            }
            Evaluator evaluator;
            if (predicatesQueue.matches("(")) {
                evaluator = consumePredicates(predicatesQueue.chompBalanced('(', ')'));
            } else if (predicatesQueue.matches("@")) {
                evaluator = byAttribute(predicatesQueue);
            } else if (predicatesQueue.matchesRegex("\\w+.*")) {
                evaluator = byFunction(predicatesQueue);
            } else {
                throw new Selector.SelectorParseException("Could not parse query '%s': unexpected token at '%s'", query, predicatesQueue.remainder());
            }
            evaluatorStack.calc(evaluator, currentOperation);
            //consume operator
            currentOperation = null;
        }
        predicatesQueue.consumeWhitespace();
    }
    evaluatorStack.mergeOr();
    return evaluatorStack.peek();
}
 
開發者ID:code4craft,項目名稱:xsoup,代碼行數:34,代碼來源:XPathParser.java

示例5: chompEqualValue

import us.codecraft.xsoup.XTokenQueue; //導入依賴的package包/類
private String chompEqualValue(XTokenQueue cq) {
    String value;
    if (cq.matchChomp("'")) {
        value = cq.chompTo("'");
    } else if (cq.matchChomp("\"")) {
        value = cq.chompTo("\"");
    } else if (cq.containsAny(" ")) {
        value = cq.chompTo(" ");
    } else {
        value = cq.remainder();
    }
    return value;
}
 
開發者ID:code4craft,項目名稱:xsoup,代碼行數:14,代碼來源:XPathParser.java

示例6: XPathParser

import us.codecraft.xsoup.XTokenQueue; //導入依賴的package包/類
public XPathParser(String xpathStr) {
    this.query = xpathStr;
    this.tq = new XTokenQueue(xpathStr);
}
 
開發者ID:code4craft,項目名稱:xsoup,代碼行數:5,代碼來源:XPathParser.java

示例7: byAttribute

import us.codecraft.xsoup.XTokenQueue; //導入依賴的package包/類
private Evaluator byAttribute(XTokenQueue cq) {
    cq.matchChomp("@");
    String key = cq.consumeToAny("=", "!=", "^=", "$=", "*=", "~="); // eq, not, start, end, contain, match, (no val)
    Validate.notEmpty(key);
    cq.consumeWhitespace();
    Evaluator evaluator;
    if (cq.isEmpty()) {
        if ("*".equals(key)) {
            evaluator = new XEvaluators.HasAnyAttribute();
        } else {
            evaluator = new Evaluator.Attribute(key);
        }
    } else {
        if (cq.matchChomp("=")) {
            String value = chompEqualValue(cq);
            //to support select one class out of all
            if (key.equals("class")) {
                String className = XTokenQueue.trimQuotes(value);
                if (!className.contains(" ")) {
                    evaluator = new Evaluator.Class(className);
                } else {
                    evaluator = new Evaluator.AttributeWithValue(key, className);
                }
            } else {
                evaluator = new Evaluator.AttributeWithValue(key, XTokenQueue.trimQuotes(value));
            }
        } else if (cq.matchChomp("!="))
            evaluator = new Evaluator.AttributeWithValueNot(key, XTokenQueue.trimQuotes(chompEqualValue(cq)));

        else if (cq.matchChomp("^="))
            evaluator = new Evaluator.AttributeWithValueStarting(key, XTokenQueue.trimQuotes(chompEqualValue(cq)));

        else if (cq.matchChomp("$="))
            evaluator = new Evaluator.AttributeWithValueEnding(key, XTokenQueue.trimQuotes(chompEqualValue(cq)));

        else if (cq.matchChomp("*="))
            evaluator = new Evaluator.AttributeWithValueContaining(key, XTokenQueue.trimQuotes(chompEqualValue(cq)));

        else if (cq.matchChomp("~="))
            evaluator = new Evaluator.AttributeWithValueMatching(key, Pattern.compile(XTokenQueue.trimQuotes(chompEqualValue(cq))));
        else
            throw new Selector.SelectorParseException("Could not parse attribute query '%s': unexpected token at '%s'", query, chompEqualValue(cq));
    }
    return evaluator;
}
 
開發者ID:code4craft,項目名稱:xsoup,代碼行數:46,代碼來源:XPathParser.java


注:本文中的us.codecraft.xsoup.XTokenQueue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。