Top Description Fields Constructors Methods
org.mortbay.util

public Class QuotedStringTokenizer

extends StringTokenizer
Class Inheritance
Imports
java.util.NoSuchElementException, .StringTokenizer

StringTokenizer with Quoting support. This class is a copy of the java.util.StringTokenizer API and the behaviour is the same, except that single and doulbe quoted string values are recognized. Delimiters within quotes are not considered delimiters. Quotes can be escaped with '\'.
Author
Greg Wilkins (gregw)
See Also
java.util.StringTokenizer

Field Summary

Modifier and TypeField and Description
private static final String
private String
private boolean
private boolean
private int
private int
private boolean
private boolean
private boolean
private String
private StringBuffer

Constructor Summary

AccessConstructor and Description
public
QuotedStringTokenizer(String str, String delim, boolean returnDelimiters, boolean returnQuotes)

public
QuotedStringTokenizer(String str, String delim, boolean returnDelimiters)

public
public

Method Summary

Modifier and TypeMethod and Description
public int
public boolean

Returns:

handle double quotes if true
getDouble
()

public boolean

Returns:

handle single quotes if true
getSingle
()

public boolean
hasMoreElements()

Overrides java.util.StringTokenizer.hasMoreElements.

Implements java.util.Enumeration.hasMoreElements.

Returns the same value as the hasMoreTokens method.
public boolean
hasMoreTokens()

Overrides java.util.StringTokenizer.hasMoreTokens.

Tests if there are more tokens available from this tokenizer's string.
public Object
nextElement()

Overrides java.util.StringTokenizer.nextElement.

Implements java.util.Enumeration.nextElement.

Returns the same value as the nextToken method, except that its declared return value is Object rather than String.
public String
nextToken()

Overrides java.util.StringTokenizer.nextToken.

Returns the next token from this string tokenizer.
public String
nextToken(String
the new delimiters.
delim
)

Overrides java.util.StringTokenizer.nextToken.

Returns the next token in this string tokenizer's string.
public static String

Returns:

quoted string
quote
(String
The string to quote.
s
,
String delim)

Quote a string.

public static String

Returns:

quoted string
quote
(String
The string to quote.
s
)

Quote a string.

public static void
quote(StringBuffer
The StringBuffer
buf
,
String
The String to quote.
s
)

Quote a string into a StringBuffer.

public static void
quoteIfNeeded(StringBuffer
The StringBuffer
buf
,
String
The String to quote.
s
)

Quote a string into a StringBuffer.

public void
setDouble(boolean
handle double quotes if true
d
)

public void
setSingle(boolean
handle single quotes if true
single
)

public static String

Returns:

quoted string
unquote
(String
The string to unquote.
s
)

Unquote a string.

Field Detail

__delimback to summary
private static final String __delim
_delimback to summary
private String _delim
_doubleback to summary
private boolean _double
_hasTokenback to summary
private boolean _hasToken
_iback to summary
private int _i
_lastStartback to summary
private int _lastStart
_returnDelimitersback to summary
private boolean _returnDelimiters
_returnQuotesback to summary
private boolean _returnQuotes
_singleback to summary
private boolean _single
_stringback to summary
private String _string
_tokenback to summary
private StringBuffer _token

Constructor Detail

QuotedStringTokenizerback to summary
public QuotedStringTokenizer(String str, String delim, boolean returnDelimiters, boolean returnQuotes)
QuotedStringTokenizerback to summary
public QuotedStringTokenizer(String str, String delim, boolean returnDelimiters)
QuotedStringTokenizerback to summary
public QuotedStringTokenizer(String str, String delim)
QuotedStringTokenizerback to summary
public QuotedStringTokenizer(String str)

Method Detail

countTokensback to summary
public int countTokens()

Overrides java.util.StringTokenizer.countTokens.

Not implemented.

Returns:int

Doc from java.util.StringTokenizer.countTokens.

the number of tokens remaining in the string using the current delimiter set.

getDoubleback to summary
public boolean getDouble()
Returns:boolean

handle double quotes if true

getSingleback to summary
public boolean getSingle()
Returns:boolean

handle single quotes if true

hasMoreElementsback to summary
public boolean hasMoreElements()

Overrides java.util.StringTokenizer.hasMoreElements.

Implements java.util.Enumeration.hasMoreElements.

Doc from java.util.StringTokenizer.hasMoreElements.

Returns the same value as the hasMoreTokens method. It exists so that this class can implement the Enumeration interface.

Returns:boolean

true if there are more tokens; false otherwise.

hasMoreTokensback to summary
public boolean hasMoreTokens()

Overrides java.util.StringTokenizer.hasMoreTokens.

Doc from java.util.StringTokenizer.hasMoreTokens.

Tests if there are more tokens available from this tokenizer's string. If this method returns true, then a subsequent call to nextToken with no argument will successfully return a token.

Returns:boolean

true if and only if there is at least one token in the string after the current position; false otherwise.

nextElementback to summary
public Object nextElement() throws NoSuchElementException

Overrides java.util.StringTokenizer.nextElement.

Implements java.util.Enumeration.nextElement.

Doc from java.util.StringTokenizer.nextElement.

Returns the same value as the nextToken method, except that its declared return value is Object rather than String. It exists so that this class can implement the Enumeration interface.

Returns:Object

the next token in the string.

Exceptions
NoSuchElementException:
if there are no more tokens in this tokenizer's string.
nextTokenback to summary
public String nextToken() throws NoSuchElementException

Overrides java.util.StringTokenizer.nextToken.

Doc from java.util.StringTokenizer.nextToken.

Returns the next token from this string tokenizer.

Returns:String

the next token from this string tokenizer.

Exceptions
NoSuchElementException:
if there are no more tokens in this tokenizer's string.
nextTokenback to summary
public String nextToken(String delim) throws NoSuchElementException

Overrides java.util.StringTokenizer.nextToken.

Doc from java.util.StringTokenizer.nextToken.

Returns the next token in this string tokenizer's string. First, the set of characters considered to be delimiters by this StringTokenizer object is changed to be the characters in the string delim. Then the next token in the string after the current position is returned. The current position is advanced beyond the recognized token. The new delimiter set remains the default after this call.

Parameters
delim:String

the new delimiters.

Returns:String

the next token, after switching to the new delimiter set.

Exceptions
NoSuchElementException:
if there are no more tokens in this tokenizer's string.
quoteback to summary
public static String quote(String s, String delim)

Quote a string. The string is quoted only if quoting is required due to embeded delimiters, quote characters or the empty string.

Parameters
s:String

The string to quote.

Returns:String

quoted string

quoteback to summary
public static String quote(String s)

Quote a string. The string is quoted only if quoting is required due to embeded delimiters, quote characters or the empty string.

Parameters
s:String

The string to quote.

Returns:String

quoted string

quoteback to summary
public static void quote(StringBuffer buf, String s)

Quote a string into a StringBuffer. The characters ", \, \n, \r, \t, \f and \b are escaped

Parameters
buf:StringBuffer

The StringBuffer

s:String

The String to quote.

quoteIfNeededback to summary
public static void quoteIfNeeded(StringBuffer buf, String s)

Quote a string into a StringBuffer. The characters ", \, \n, \r, \t, \f, \b are escaped. Quotes are forced if any escaped characters are present or there is a ", ', space, + or % character.

Parameters
buf:StringBuffer

The StringBuffer

s:String

The String to quote.

setDoubleback to summary
public void setDouble(boolean d)
Parameters
d:boolean

handle double quotes if true

setSingleback to summary
public void setSingle(boolean single)
Parameters
single:boolean

handle single quotes if true

unquoteback to summary
public static String unquote(String s)

Unquote a string.

Parameters
s:String

The string to unquote.

Returns:String

quoted string