if (ch == EQUALS) {
state = ParseState.WaitingForGreater;
continue;
} else {
throw new HStoreParseException("Expected '=>' key-value separator", position);
}
case WaitingForGreater :
if (ch == GREATER) {
state = ParseState.WaitingForValue;
continue;
} else {
throw new HStoreParseException("Expected '=>' key-value separator", position);
}
case WaitingForValue :
if (Character.isWhitespace(ch)) {
continue;
}
if (ch == QUOTE) {
elementValue = advanceQuoted();
} else {
// we have non-quote char, so start loading the key
elementValue = advanceWord(COMMA);
// hstore supports NULL values, so if unquoted NULL is there, it is rewritten to null
if (NULL.equalsIgnoreCase(elementValue)) {
elementValue = null;
}
}
state = ParseState.WaitingForComma;
continue;
case WaitingForComma :
if (Character.isWhitespace(ch)) {
continue;
}
if (ch == COMMA) {
// we are done
break loop;
} else {
throw new HStoreParseException("Cannot find comma as an end of the value: '" + value + "'",
position);
}
default :
throw new IllegalStateException("Unknown HStoreParser state");
}
} // loop
// here we either consumed whole string or we found a comma
if (state == ParseState.WaitingForKey) {
// string was consumed when waiting for key, so we are done with processing
nextEntry = null;
return;
}
if (state != ParseState.WaitingForComma) {
throw new HStoreParseException("Unexpected end of string", position);
}
if (elementKey == null) {
throw new HStoreParseException("Internal parsing error", position);
}
// init nextValue
nextEntry = new HStoreEntry(elementKey, elementValue);
}