FileDocCategorySizeDatePackage
StringTokenizer.javaAPI DocApache Ant 1.704755Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.util

StringTokenizer

public class StringTokenizer extends org.apache.tools.ant.ProjectComponent implements Tokenizer
Class to tokenize the input as areas separated by white space, or by a specified list of delim characters. Behaves like java.util.StringTokenizer. If the stream starts with delim characters, the first token will be an empty string (unless the treat delims as tokens flag is set).
since
Ant 1.7

Fields Summary
private String
intraString
private int
pushed
private char[]
delims
private boolean
delimsAreTokens
private boolean
suppressDelims
private boolean
includeDelims
Constructors Summary
Methods Summary
public java.lang.StringgetPostToken()

return
the intratoken string

        return suppressDelims || includeDelims ? "" : intraString;
    
public java.lang.StringgetToken(java.io.Reader in)
find and return the next token

param
in the input stream
return
the token
exception
IOException if an error occurs reading

        int ch = -1;
        if (pushed != -2) {
            ch = pushed;
            pushed = -2;
        } else {
            ch = in.read();
        }
        if (ch == -1) {
            return null;
        }
        boolean inToken = true;
        intraString = "";
        StringBuffer word = new StringBuffer();
        StringBuffer padding = new StringBuffer();
        while (ch != -1) {
            char c = (char) ch;
            boolean isDelim = isDelim(c);
            if (inToken) {
                if (isDelim) {
                    if (delimsAreTokens) {
                        if (word.length() == 0) {
                            word.append(c);
                        } else {
                            pushed = ch;
                        }
                        break;
                    }
                    padding.append(c);
                    inToken = false;
                } else {
                    word.append(c);
                }
            } else {
                if (isDelim) {
                    padding.append(c);
                } else {
                    pushed = ch;
                    break;
                }
            }
            ch = in.read();
        }
        intraString = padding.toString();
        if (includeDelims) {
            word.append(intraString);
        }
        return word.toString();
    
private booleanisDelim(char ch)

        if (delims == null) {
            return Character.isWhitespace(ch);
        }
        for (int i = 0; i < delims.length; ++i) {
            if (delims[i] == ch) {
                return true;
            }
        }
        return false;
    
public voidsetDelims(java.lang.String delims)
attribute delims - the delimiter characters

param
delims a string containing the delimiter characters


                       
        
        this.delims = StringUtils.resolveBackSlash(delims).toCharArray();
    
public voidsetDelimsAreTokens(boolean delimsAreTokens)
attribute delimsaretokens - treat delimiters as separate tokens.

param
delimsAreTokens true if delimiters are to be separate

        this.delimsAreTokens = delimsAreTokens;
    
public voidsetIncludeDelims(boolean includeDelims)
attribute includedelims - treat delimiters as part of the token. default - false

param
includeDelims if true add delimiters to the token

        this.includeDelims = includeDelims;
    
public voidsetSuppressDelims(boolean suppressDelims)
attribute suppressdelims - suppress delimiters. default - false

param
suppressDelims if true do not report delimiters

        this.suppressDelims = suppressDelims;