Class PushbackTokenizer
- java.lang.Object
-
- org.openstreetmap.josm.data.osm.search.PushbackTokenizer
-
public class PushbackTokenizer extends java.lang.Object
This class is used to parse a search string and split it into tokens. It provides methods to parse numbers and extract strings.- Since:
- 12656 (moved from actions.search package)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PushbackTokenizer.Range
A range of long numbers.static class
PushbackTokenizer.Token
The token types that may be read
-
Field Summary
Fields Modifier and Type Field Description private int
c
private java.lang.Long
currentNumber
private java.lang.Long
currentRange
private java.lang.String
currentText
private PushbackTokenizer.Token
currentToken
private boolean
isRange
private java.io.Reader
search
private static java.util.List<java.lang.Character>
SPECIAL_CHARS
private static java.util.List<java.lang.Character>
SPECIAL_CHARS_QUOTED
-
Constructor Summary
Constructors Constructor Description PushbackTokenizer(java.io.Reader search)
Creates a newPushbackTokenizer
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
getChar()
long
getReadNumber()
Gets the last number that was readprivate java.lang.String
getString()
private java.lang.String
getString(boolean quoted)
java.lang.String
getText()
Gets the last text that was foundPushbackTokenizer.Token
nextToken()
The token returned isnull
or starts with an identifier character: - for an '-'.boolean
readIfEqual(PushbackTokenizer.Token token)
Reads the next token if it is equal to the given, suggested tokenlong
readNumber(java.lang.String errorMessage)
Reads a numberPushbackTokenizer.Range
readRange(java.lang.String errorMessage)
Reads a range of numbersjava.lang.String
readTextOrNumber()
Reads the next token.
-
-
-
Field Detail
-
search
private final java.io.Reader search
-
currentToken
private PushbackTokenizer.Token currentToken
-
currentText
private java.lang.String currentText
-
currentNumber
private java.lang.Long currentNumber
-
currentRange
private java.lang.Long currentRange
-
c
private int c
-
isRange
private boolean isRange
-
SPECIAL_CHARS
private static final java.util.List<java.lang.Character> SPECIAL_CHARS
-
SPECIAL_CHARS_QUOTED
private static final java.util.List<java.lang.Character> SPECIAL_CHARS_QUOTED
-
-
Constructor Detail
-
PushbackTokenizer
public PushbackTokenizer(java.io.Reader search)
Creates a newPushbackTokenizer
- Parameters:
search
- The search string reader to read the tokens from
-
-
Method Detail
-
getChar
private void getChar()
-
getString
private java.lang.String getString(boolean quoted)
-
getString
private java.lang.String getString()
-
nextToken
public PushbackTokenizer.Token nextToken()
The token returned isnull
or starts with an identifier character: - for an '-'. This will be the only character : for an key. The value is the next token | for "OR" ^ for "XOR" ' ' for anything else.- Returns:
- The next token in the stream.
-
readIfEqual
public boolean readIfEqual(PushbackTokenizer.Token token)
Reads the next token if it is equal to the given, suggested token- Parameters:
token
- The token the next one should be equal to- Returns:
true
if it has been read
-
readTextOrNumber
public java.lang.String readTextOrNumber()
Reads the next token. If it is a text, return that text. If not, advance- Returns:
- the text or
null
if the reader was advanced
-
readNumber
public long readNumber(java.lang.String errorMessage) throws SearchParseError
Reads a number- Parameters:
errorMessage
- The error if the number cannot be read- Returns:
- The number that was found
- Throws:
SearchParseError
- if there is no number
-
getReadNumber
public long getReadNumber()
Gets the last number that was read- Returns:
- The last number
-
readRange
public PushbackTokenizer.Range readRange(java.lang.String errorMessage) throws SearchParseError
Reads a range of numbers- Parameters:
errorMessage
- The error if the input is malformed- Returns:
- The range that was found
- Throws:
SearchParseError
- If the input is not as expected for a range
-
getText
public java.lang.String getText()
Gets the last text that was found- Returns:
- The text
-
-