commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Inger, Matthew" <in...@Synygy.com>
Subject RE: suggestion for new StringUtils.method
Date Wed, 12 Nov 2003 00:08:13 GMT
I've come up with the following class for this.
(I also have a test class which tests a few of the
 simple cases).  Token parsing is done semi-lazily,
in that when the first token is requested (or the
token count), the whole thing is parsed.  And the
reset forgets about the tokens, so you can change
parameters, and re-parse.


public class DelimitedTokenizer
{
    public static final char DEFAULT_DELIMITER = ',';
    public static final char DEFAULT_QUOTE = '"';
    public static final String WHITESPACE = " \t\n\r";

    public DelimitedTokenizer(String input);
    public DelimitedTokenizer(String input, char delim);
    public DelimitedTokenizer(String input, char delim, char quote);

    public char getDelim();
    public void setDelim(char delim);

    public char getQuote();
    public void setQuote(char quote);

    // defaults to true
    public boolean isIgnoreLeadingWhitespace();
    public void setIgnoreLeadingWhitespace(boolean ignoreLeadingWhitespace);

    // defaults to true
    public boolean isIgnoreTrailingWhitespace();
    public void setIgnoreTrailingWhitespace(boolean
ignoreTrailingWhitespace);

    // defaults to false
    public boolean isTreatEmptyAsNull();
    public void setTreatEmptyAsNull(boolean treatEmptyAsNull);

    public int countTokens();
    public String nextToken();
    public void reset();
    public String [] getAllTokens();
}


Now the question is how to submit it....

-----Original Message-----
From: J.Pietschmann [mailto:j3322ptm@yahoo.de]
Sent: Tuesday, November 11, 2003 2:28 PM
To: Jakarta Commons Developers List
Subject: Re: suggestion for new StringUtils.method


Inger, Matthew wrote:
> String [] undelimit(String input, char separatorChar, char quoteChar);

It's a tokenizer. It would be handy to have it as an iterator pattern
too (like StringTokenizer).

J.Pietschmann



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message