/** Returns a substring of this from the current position to the end argument */ public String substring(int end) { return string().substring(position(),end); }
/** Returns the substring of this string from the current position to the end */ public String substring() { return string().substring(position()); }
protected int findEndOfKey() { for (int peekI=s.position(); peekI<s.string().length(); peekI++) { if (s.string().charAt(peekI)==':' || s.string().charAt(peekI)==',') return peekI; } return -1; }
protected int findEndOfValue() { for (int peekI=s.position(); peekI<s.string().length(); peekI++) { if (s.string().charAt(peekI)==',' || s.string().charAt(peekI)=='}') return peekI; } return -1; }
@Override public void parse(String s) { if (s == null || s.length() == 0) return; super.parse(s); if (string().position() != string().string().length()) { throw new IllegalArgumentException("Expected end of string " + string().at()); } }
protected void consumeValue(String key) { // find the next comma or bracket, whichever is next int endOfValue=findEndOfValue(); if (endOfValue<0) { throw new IllegalArgumentException("Expected a value followed by ',' or '}' " + s.at()); } try { handleKeyValue(key, s.substring(endOfValue)); s.setPosition(endOfValue); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Expected a legal value from position " + s.position() + " to " + endOfValue + " but was '" + s.substring(endOfValue) + "'", e); } }
/** * Adds attributes with the specified bitmap to normalizer. * @param attribute Attribute to add * @param value Value of attribute * @param bitmap Bitmap as a list of bits, e.g. '[0, 3, 45]' */ private void parseBitmapList(String attribute, String value, String bitmap) { PositionedString s = new PositionedString(bitmap); s.consume('['); BigInteger mask = BigInteger.ZERO; while (!s.peek(']')) { s.consumeSpaces(); int pos = findNextButSkipLists(new char[]{',',']'}, s.string(), s.position()); if (pos == -1) { break; } int subqueryIndex = Integer.parseUnsignedInt(s.substring(pos).trim()); if (subqueryIndex > 63 || subqueryIndex < 0) { throw new IllegalArgumentException("Subquery index must be in the range 0-63"); } mask = mask.or(BigInteger.ONE.shiftLeft(subqueryIndex)); s.setPosition(pos); s.consumeOptional(','); s.consumeSpaces(); } addAttribute(attribute, value, mask); }