org.moremotion.util
Class StringParser

java.lang.Object
  extended by org.moremotion.util.StringParser

public class StringParser
extends java.lang.Object

String Parser parses the items in a string with the specified delimiter. The difference of this class from the java.util.StringTokenizer is that this class ignores the delimiters enclosed with (), [], {} , '', "" characters.

Example:

 StringParser sp = new StringParser("(xxx,yyy)',',[(qqq,www),(ppp,rrr)],zzz",',');
 sp.nextItem(); // returns "(xxx,yyy)','"
 sp.nextItem(); // returns "[(qqq,www),(ppp,rrr)]
 sp.nextItem(); // returns "zzz"
 

Version:
$Id: StringParser.java 51 2008-03-10 11:46:54Z erkan $

Constructor Summary
StringParser(java.lang.String str, char dlm)
          Creates a new StringParser
 
Method Summary
 boolean eos()
          Returns true if end of string is reached.
static java.lang.String extractParameter(java.lang.String str, java.lang.String param)
          This static method extracts the values of the parameters existing in a string in parm1=parm1value; parm2=parm2 value; format.
 java.lang.String firstItem()
          Returns the first item in the string.
 boolean hasMore()
           
 int itemCount()
          Returns the next item in the string.
static int locateChar(java.lang.StringBuffer buffer, int startPos, char c)
          This static method returns the position of the specified character in the given string buffer.
static int locateChar(java.lang.String str, int startPos, char c)
          This static method returns the position of the specified character in the given string.
static void main(java.lang.String[] args)
           
 java.lang.String nextEnclosed()
           
 java.lang.String nextItem()
          Returns the next item in the string.
 boolean nextItemAsBoolean()
          Returns the next item as boolean.
 int nextItemAsInt(int defValue)
          Returns the next item as int and if next item is not a number it returns the default value.
 void reset()
          Moves the cursor to the first position.
 void trimmed()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringParser

public StringParser(java.lang.String str,
                    char dlm)
Creates a new StringParser

Method Detail

eos

public boolean eos()
Returns true if end of string is reached.


hasMore

public boolean hasMore()

trimmed

public void trimmed()

firstItem

public java.lang.String firstItem()
Returns the first item in the string.


nextItem

public java.lang.String nextItem()
Returns the next item in the string.


itemCount

public int itemCount()
Returns the next item in the string.


reset

public void reset()
Moves the cursor to the first position.


nextItemAsInt

public int nextItemAsInt(int defValue)
Returns the next item as int and if next item is not a number it returns the default value.


nextEnclosed

public java.lang.String nextEnclosed()

nextItemAsBoolean

public boolean nextItemAsBoolean()
Returns the next item as boolean. If the next item is not "true" returns false.


locateChar

public static int locateChar(java.lang.String str,
                             int startPos,
                             char c)
This static method returns the position of the specified character in the given string. The chars enclosed with (), [], {} , '', "" characters are ignored.

Parameters:
str - The string where c will be searched.
startPos - Search Start Position
c - The character to be searched.
Returns:
The position of the c in the str. If c is not found -1 is returned.

locateChar

public static int locateChar(java.lang.StringBuffer buffer,
                             int startPos,
                             char c)
This static method returns the position of the specified character in the given string buffer. The chars enclosed with (), [], {} , '', "" characters are ignored.

Parameters:
buffer - The string buffer where c will be searched.
startPos - Search Start Position
c - The character to be searched.
Returns:
The position of the c in the str. If c is not found -1 is returned.

extractParameter

public static java.lang.String extractParameter(java.lang.String str,
                                                java.lang.String param)
This static method extracts the values of the parameters existing in a string in parm1=parm1value; parm2=parm2 value; format.

Parameters:
str - The string where param will be searched.
param - The name of the parameter whose value to be extracted.
Returns:
The value of the parameter

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception


Copyright © 2002-2008 MOR YAZILIM. All Rights Reserved.