|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.hk2.component.KeyValuePairParser
public final class KeyValuePairParser
Parses a string like key=value,key=value,key=value.
More specifically the format of the line satisfies the following BNF constructions:
LINE = TOKEN ( ',' LINE )? // LINE is ','-separated TOKENs TOKEN = KEY ( '=' VALUE )? // TOKEN is a key/value pair. value is optional. KEY = [^,=]+ // KEY is a non-empty string that doesn't contain ',' nor '=' VALUE = '"' ([^"]| '\' ANYCHAR )* '"' // VALUE is any string surrounded by quotes/doublequotes (where \ is used as escape), or ... VALUE = ''' ([^']| '\' ANYCHAR )* ''' VALUE = [^,]* // possibly empty string that doesn't contain ','
This class works like StringTokenizer
; each time parseNext()
is invoked, the parser "moves" to the next key/value pair, which
you can then obtain with getKey()
and getValue()
.
The hasNext()
method shall be used to check if there's a next key/value
pair after the current position.
TODO: improved error check
Constructor Summary | |
---|---|
KeyValuePairParser()
|
|
KeyValuePairParser(java.lang.String s)
|
Method Summary | |
---|---|
java.lang.String |
find(java.lang.String key)
Skips until we find the value of the given key, and leaves the parser at that point. |
java.lang.Iterable<java.lang.String> |
findAll(java.lang.String key)
Finds all the values of the given key. |
java.lang.String |
getKey()
|
java.lang.String |
getLine()
Gets the whole line. |
java.lang.String |
getValue()
|
boolean |
hasNext()
|
void |
parseNext()
|
void |
rewind()
Moves the parser to the head of the key/value pair, to reparse the same string. |
void |
set(java.lang.String str)
Resets the parser to parse the given string that looks like "key=value,key=value,..." |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public KeyValuePairParser()
public KeyValuePairParser(java.lang.String s)
Method Detail |
---|
public void set(java.lang.String str)
public boolean hasNext()
public void parseNext()
public java.lang.String getKey()
public java.lang.String getValue()
public void rewind()
public java.lang.String find(java.lang.String key)
This method is not terribly efficient, but it is convenient.
public java.lang.Iterable<java.lang.String> findAll(java.lang.String key)
public java.lang.String getLine()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |