JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util
Class JCStringTokenizer

java.lang.Object
  |
  +--com.klg.jclass.util.JCStringTokenizer

public class JCStringTokenizer
extends Object

JCStringTokenizer controls simple linear tokenization of a String. The set of delimiters, which defaults to common whitespace characters, can be specified either during creation or on a per-token basis.

It is similar to java.util.StringTokenizer, but delimiters can be included as literals by preceding them with a backslash character (the default).

It also fixes a known problem: if one delimiter immediately follows another, a null String is returned as the token instead of being skipped over.

Example usage:

  String token, s = "this, is, a,, test";
  JCStringTokenizer st = new JCStringTokenizer(s);
  while (st.hasMoreTokens()) {
      token = st.nextToken(',');
      println(token);
  }
 
This prints the following to the console:
  this
  is
  a

  test
 


Field Summary
protected  char escape_char
           
 boolean strip_esc
           
 
Constructor Summary
JCStringTokenizer(String s)
          Creates a tokenizer based on the specified String.
JCStringTokenizer(String s, boolean trim)
           
JCStringTokenizer(String s, char delim)
           
 
Method Summary
 int countTokens(char delim)
          Returns the next number of tokens in the String using the specified delimiter.
 char getEscapeChar()
          Gets the escape char (default is \).
 int getPosition()
          Returns the current scan position within the String.
 boolean hasMoreTokens()
          Returns true if more tokens exist.
 String nextToken()
          Gets the next whitespace-delimited token.
 String nextToken(char delim)
          Gets the next token from delimited String.
static String[] parse(String s, char delim)
          Parses the String using the specified delimiter.
static String[] parse(String s, char delim, char escape_char)
          Parses the String using the specified delimiter and escape char.
static String[] parseWhitespaceDelim(String s, char delim, char escape_char)
           
 void setEscapeChar(char c)
          Sets the escape char (default is \).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

strip_esc

public boolean strip_esc

escape_char

protected char escape_char
Constructor Detail

JCStringTokenizer

public JCStringTokenizer(String s)
Creates a tokenizer based on the specified String.

Parameters:
s -

JCStringTokenizer

public JCStringTokenizer(String s,
                         boolean trim)

JCStringTokenizer

public JCStringTokenizer(String s,
                         char delim)
Method Detail

parse

public static String[] parse(String s,
                             char delim)
Parses the String using the specified delimiter.

Parameters:
delim -
s -
Returns:
See Also:
nextToken()

parse

public static String[] parse(String s,
                             char delim,
                             char escape_char)
Parses the String using the specified delimiter and escape char.

Parameters:
delim -
escape_char -
s -
Returns:
See Also:
setEscapeChar(char), nextToken()

parseWhitespaceDelim

public static String[] parseWhitespaceDelim(String s,
                                            char delim,
                                            char escape_char)

getEscapeChar

public char getEscapeChar()
Gets the escape char (default is \).

Returns:

setEscapeChar

public void setEscapeChar(char c)
Sets the escape char (default is \). If 0, no escape char is used.

Parameters:
c -

nextToken

public String nextToken()
Gets the next whitespace-delimited token.

Returns:

nextToken

public String nextToken(char delim)
Gets the next token from delimited String.

The delimeter can be "escaped" by a backslash character.

To include a backslash character, precede it by another backslash character.

Parameters:
delim -
Returns:

countTokens

public int countTokens(char delim)
Returns the next number of tokens in the String using the specified delimiter.

Parameters:
delim - the delimiter
Returns:
next number of tokens in the String using the specified delimiter

hasMoreTokens

public boolean hasMoreTokens()
Returns true if more tokens exist.

Returns:
true if more tokens exist

getPosition

public int getPosition()
Returns the current scan position within the String.

Returns:
current scan position within the String

Copyright © 2004 Quest Software Inc..
All rights reserved.