/** Tests if the next characters match any of the sequences. Case insensitive. @param seq list of strings to case insensitively check for @return true of any matched, false if none did */ public boolean matchesAny(String... seq) { for (String s : seq) { if (matches(s)) return true; } return false; }
private String consumeSubQuery() { StringBuilder sq = new StringBuilder(); while (!tq.isEmpty()) { if (tq.matches("(")) sq.append("(").append(tq.chompBalanced('(', ')')).append(")"); else if (tq.matches("[")) sq.append("[").append(tq.chompBalanced('[', ']')).append("]"); else if (tq.matchesAny(combinators)) break; else sq.append(tq.consume()); } return sq.toString(); }
else if (tq.matchChomp(".")) byClass(); else if (tq.matchesWord() || tq.matches("*|")) byTag(); else if (tq.matches("[")) byAttribute(); else if (tq.matchChomp("*")) else if (tq.matchChomp(":eq(")) indexEquals(); else if (tq.matches(":has(")) has(); else if (tq.matches(":contains(")) contains(false); else if (tq.matches(":containsOwn(")) contains(true); else if (tq.matches(":containsData(")) containsData(); else if (tq.matches(":matches(")) matches(false); else if (tq.matches(":matchesOwn(")) matches(true); else if (tq.matches(":not(")) not(); else if (tq.matchChomp(":nth-child("))
/** * Tests if the queue matches the sequence (as with match), and if they do, removes the matched string from the * queue. * @param seq String to search for, and if found, remove from queue. * @return true if found and removed, false if not found. */ public boolean matchChomp(String seq) { if (matches(seq)) { pos += seq.length(); return true; } else { return false; } }
/** * Consumes the supplied sequence of the queue. If the queue does not start with the supplied sequence, will * throw an illegal state exception -- but you should be running match() against that condition. <p> Case insensitive. * @param seq sequence to remove from head of queue. */ public void consume(String seq) { if (!matches(seq)) throw new IllegalStateException("Queue did not match expected sequence"); int len = seq.length(); if (len > remainingLength()) throw new IllegalStateException("Queue not long enough to consume sequence"); pos += len; }
public String consumeToIgnoreCase(String seq) { int start = pos; String first = seq.substring(0, 1); boolean canScan = first.toLowerCase().equals(first.toUpperCase()); // if first is not cased, use index of while (!isEmpty()) { if (matches(seq)) break; if (canScan) { int skip = queue.indexOf(first, pos) - pos; if (skip == 0) // this char is the skip char, but not match, so force advance of pos pos++; else if (skip < 0) // no chance of finding, grab to end pos = queue.length(); else pos += skip; } else pos++; } return queue.substring(start, pos); }
private List<Node> parse() { while (!tq.isEmpty()) { if (tq.matches("<!--")) { parseComment(); } else if (tq.matches("<![CDATA[")) { parseCdata(); } else if (tq.matches("<?") || tq.matches("<!")) { parseXmlDecl(); } else if (tq.matches("</")) { parseEndTag(); } else if (tq.matches("<")) { parseStartTag(); } else { parseTextNode(); } } // Pop off body as it is already inside html. Iterator<Node> iterator = stack.iterator(); while (iterator.hasNext()) { if (iterator.next().nodeName().equals(bodyTag.getName())) { iterator.remove(); } } return stack; }
private List<Node> parse() { while (!tq.isEmpty()) { if (tq.matches("<!--")) { parseComment(); } else if (tq.matches("<![CDATA[")) { parseCdata(); } else if (tq.matches("<?") || tq.matches("<!")) { parseXmlDecl(); } else if (tq.matches("</")) { parseEndTag(); } else if (tq.matches("<") && !isRawDataTag(stack.peek())) { parseStartTag(); } else { parseTextNode(); } } // Pop off body as it is already inside html. Iterator<Node> iterator = stack.iterator(); while (iterator.hasNext()) { if (iterator.next().nodeName().equals(bodyTag.getName())) { iterator.remove(); } } return stack; }
private List<Node> parse() { while (!tq.isEmpty()) { if (tq.matches("<!--")) { parseComment(); } else if (tq.matches("<![CDATA[")) { parseCdata(); } else if (tq.matches("<?") || tq.matches("<!")) { parseXmlDecl(); } else if (tq.matches("</")) { parseEndTag(); } else if (tq.matches("<") && !isRawDataTag(stack.peek())) { parseStartTag(); } else { parseTextNode(); } } // Pop off body as it is already inside html. Iterator<Node> iterator = stack.iterator(); while (iterator.hasNext()) { if (iterator.next().nodeName().equals(bodyTag.getName())) { iterator.remove(); } } return stack; }