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); } }
@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()); } }
/** * Parses a map on the form <code>{key1:value1,key2:value2 ...}</code> * * @param string the textual representation of the map */ public void parse(String string) { try { this.s=new PositionedString(string); s.consumeSpaces(); s.consume('{'); while ( ! s.peek('}')) { s.consumeSpaces(); String key=consumeKey(); s.consume(':'); s.consumeSpaces(); consumeValue(key); s.consumeOptional(','); s.consumeSpaces(); } s.consume('}'); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("'" + s + "' is not a legal sparse vector string",e); } }
private String consumeKey() { if (s.consumeOptional('"')) { String key=s.consumeTo('"'); s.consume('"'); return key; } else if (s.consumeOptional('\'')) { String key=s.consumeTo('\''); s.consume('\''); return key; } else { int keyEnd=findEndOfKey(); if (keyEnd<0) throw new IllegalArgumentException("Expected a key followed by ':' " + s.at()); return s.consumeToPosition(keyEnd); } }