当前位置: 首页>>代码示例>>Java>>正文


Java XTokenQueue.consumeWhitespace方法代码示例

本文整理汇总了Java中us.codecraft.xsoup.XTokenQueue.consumeWhitespace方法的典型用法代码示例。如果您正苦于以下问题:Java XTokenQueue.consumeWhitespace方法的具体用法?Java XTokenQueue.consumeWhitespace怎么用?Java XTokenQueue.consumeWhitespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在us.codecraft.xsoup.XTokenQueue的用法示例。


在下文中一共展示了XTokenQueue.consumeWhitespace方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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.consumeWhitespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。