Back to index

wims  3.65+svn20090927
Public Member Functions | Package Attributes
rene.util.parser.StringParser Class Reference

This is a string simple parser. More...

List of all members.

Public Member Functions

 StringParser (String S)
boolean blank ()
boolean blank (char c)
String upto (char c)
 Cut off the String upto a character c.
boolean advance ()
 Advance one character.
String parseword ()
 Parse a word up to a blank.
String parsedigits (char c)
 Parse digits upto the character c or blank.
String parsedigits ()
 Parse digits upto a blank.
String parseword (char c)
 Parse a word upto the character c or blank.
boolean isint ()
int parseint ()
 Parse an int upto a blank.
int parseint (char c)
 Parse an int upto a blank or c.
void skipblanks ()
 Skip all white characters.
boolean skip (String s)
 Skip everything to the string s.
char next ()
 Get the next character.
String wrapline (int columns)
 Return a String, which is parsed from words with limited length.
Vector wraplines (int columns)
 Parse the string into lines.
String wraplineword (int columns)
Vector wrapwords (int columns)
void replace (char c1, char c2)
 Replace c1 by c2.
boolean error ()

Package Attributes

char C []
int N
int L
boolean Error

Detailed Description

This is a string simple parser.

Definition at line 9 of file StringParser.java.


Constructor & Destructor Documentation

Parameters:
Sthe string to be parsed.

Definition at line 17 of file StringParser.java.

       {      C=S.toCharArray();
              N=0;
              L=C.length;
              Error=(N>=L);
       }

Member Function Documentation

Advance one character.

Returns:
String is not empty.

Definition at line 55 of file StringParser.java.

       {      if (N<L) N++;
              if (N>=L) Error=true;
              return !Error;
       }

Here is the caller graph for this function:

Returns:
next character is white?

Definition at line 27 of file StringParser.java.

       {      return (C[N]==' ' || C[N]=='\t' || C[N]=='\n' || C[N]=='\r');
       }

Here is the caller graph for this function:

Returns:
next character is white or c?

Definition at line 34 of file StringParser.java.

       {      return (C[N]==' ' || C[N]=='\t' || C[N]=='\n' || C[N]=='\r' || C[N]==c);
       }
Returns:
if an error has occured during the parsing.

Definition at line 296 of file StringParser.java.

{ return Error; }
Returns:
next character is a digit?

Definition at line 122 of file StringParser.java.

       {      if (Error) return false;
              return (C[N]>='0' && C[N]<='9');
       }

Get the next character.

Definition at line 193 of file StringParser.java.

       {      if (Error) return ' ';
              else
              {      N++;
                     if (N>=L) { Error=true; }
                     return C[N-1];
              }
       }
String rene.util.parser.StringParser.parsedigits ( char  c) [inline]

Parse digits upto the character c or blank.

Definition at line 77 of file StringParser.java.

       {      if (Error) return "";
              while (blank())
              {      if (!advance()) return "";
              }
              int n=N;
              while (!Error && !blank())
              {      if (N>L || C[N]<'0' || C[N]>'9' || C[N]==c) break;
                     advance();
              }
              return new String(C,n,N-n);
       }

Here is the call graph for this function:

Parse digits upto a blank.

Definition at line 93 of file StringParser.java.

       {      if (Error) return "";
              while (blank())
              {      if (!advance()) return "";
              }
              int n=N;
              while (!Error && !blank())
              {      if (N>L || C[N]<'0' || C[N]>'9') break;
                     advance();
              }
              return new String(C,n,N-n);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Parse an int upto a blank.

The int may be negative.

Returns:
the int

Definition at line 131 of file StringParser.java.

       {      int sig=1;
              try
              {      skipblanks(); if (Error) return 0;
                     if (C[N]=='-')
                     {      sig=-1;
                            N++;
                            if (N>L) { Error=true; return 0; }
                     }
                     return sig*Integer.parseInt(parsedigits(),10);
              }
              catch (NumberFormatException e)
              {      return 0;
              }
       }

Here is the call graph for this function:

Here is the caller graph for this function:

int rene.util.parser.StringParser.parseint ( char  c) [inline]

Parse an int upto a blank or c.

The int may be negative.

Returns:
the int

Definition at line 151 of file StringParser.java.

       {      int sig=1;
              try
              {      skipblanks(); if (Error) return 0;
                     if (C[N]=='-')
                     {      sig=-1;
                            N++;
                            if (N>L) { Error=true; return 0; }
                     }
                     return sig*Integer.parseInt(parsedigits(c),10);
              }
              catch (NumberFormatException e)
              {      return 0;
              }
       }

Here is the call graph for this function:

Parse a word up to a blank.

Definition at line 64 of file StringParser.java.

       {      if (Error) return "";
              while (blank())
              {      if (!advance()) return "";
              }
              int n=N;
              while (!Error && !blank()) advance();
              return new String(C,n,N-n);
       }

Here is the call graph for this function:

String rene.util.parser.StringParser.parseword ( char  c) [inline]

Parse a word upto the character c or blank.

Definition at line 109 of file StringParser.java.

       {      if (Error) return "";
              while (blank())
              {      if (!advance()) return "";
              }
              int n=N;
              while (!Error && !blank(c)) advance();
              return new String(C,n,N-n);
       }

Here is the call graph for this function:

void rene.util.parser.StringParser.replace ( char  c1,
char  c2 
) [inline]

Replace c1 by c2.

Definition at line 288 of file StringParser.java.

       {      for (int i=0; i<L; i++)
                     if (C[i]==c1) C[i]=c2;
       }

Here is the caller graph for this function:

Skip everything to the string s.

Returns:
String was found

Definition at line 180 of file StringParser.java.

       {      if (Error) return false;
              int l=s.length();
              if (N+l>L) return false;
              if (!new String(C,N,l).equals(s)) return false;
              N+=l;
              if (N>=L) Error=true;
              return true;
       }

Skip all white characters.

Definition at line 170 of file StringParser.java.

       {      if (Error) return;
              while (blank())
                     if (!advance()) break;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

String rene.util.parser.StringParser.upto ( char  c) [inline]

Cut off the String upto a character c.

Definition at line 41 of file StringParser.java.

       {      if (Error) return "";
              int n=N;
              while (n<L && C[n]!=c) n++;
              if (n>=L) Error=true;
              String s=new String(C,N,n-N);
              N=n;
              return s;
       }
String rene.util.parser.StringParser.wrapline ( int  columns) [inline]

Return a String, which is parsed from words with limited length.

Parameters:
columnsthe maximal length of the string

Definition at line 206 of file StringParser.java.

       {      int n=N,good=N;
              String s="";
              while (n<L)
              {      if (C[n]=='\n')
                     {      if (n>N) s=new String(C,N,n-N);
                            N=n+1;
                            break;
                     }
                     if (C[n]==' ' || C[n]=='\t' || C[n]=='\n')
                     {      good=n;
                     }
                     n++;
                     if (n-N>=columns && good>N)
                     {      s=new String(C,N,good-N);
                            N=good+1;
                            break;
                     }
                     if (n>=L)
                     {      if (n>N) s=new String(C,N,n-N);
                            N=n;
                            break;
                     }
              }
              if (N>=L) Error=true;
              return s;
       }

Here is the caller graph for this function:

Vector rene.util.parser.StringParser.wraplines ( int  columns) [inline]

Parse the string into lines.

Parameters:
columnsthe maximal length of each line
Returns:
a Vector with lines

Definition at line 239 of file StringParser.java.

       {      Vector v=new Vector(10,10);
              String s;
              while (!Error)
              {      s=wrapline(columns);
                     v.addElement(s);
              }
              return v;
       }

Here is the call graph for this function:

Here is the caller graph for this function:

String rene.util.parser.StringParser.wraplineword ( int  columns) [inline]

Definition at line 249 of file StringParser.java.

       {      int n=N,good=N;
              String s="";
              while (n<L)
              {      if (C[n]=='\n')
                     {      s=new String(C,N,n-N);
                            N=n+1;
                            break;
                     }
                     n++;
                     if (n>=L)
                     {      if (n>N) s=new String(C,N,n-N);
                            N=n;
                            break;
                     }
                     if (n-N>=columns && good>N)
                     {      s=new String(C,N,good-N);
                            N=good+1;
                            if (N<L && C[N]!='\n') s=s+"\\";
                            break;
                     }
              }
              if (N>=L) Error=true;
              return s;
       }

Here is the caller graph for this function:

Vector rene.util.parser.StringParser.wrapwords ( int  columns) [inline]

Definition at line 275 of file StringParser.java.

       {      Vector v=new Vector(10,10);
              String s;
              while (!Error)
              {      s=wraplineword(columns);
                     v.addElement(s);
              }
              return v;
       }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 10 of file StringParser.java.

Definition at line 12 of file StringParser.java.

Definition at line 11 of file StringParser.java.

Definition at line 11 of file StringParser.java.


The documentation for this class was generated from the following file: