Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## things.common.tools
Class StringScanner

    java.lang.Object
      things.common.tools.StringScanner

    public class StringScanner

extends java.lang.Object

A String Scanner. It's not for matching, parsing, or anything like that. Use if for very simple in-order string searches.

Version:
  1.0

  Version History

      EPG - Rewrite from another project - 7 JUN 07

Author:
  Erich P. Gatejen

Constructor Summary
`StringScanner()`

Method Summary
`void` | `addpattern(java.lang.String patternName, java.lang.String pattern)` Adds a regex pattern to the scanner.
`int` | `find(java.lang.String patternName)` Find a pattern.
`int` | `get()` Get the cursor position
`java.lang.String` | `getData()` Get the string being scanned.
`void` | `move(int offset)` Move the cursor by an offset.
`void` | `reset()` Resets the cursor to the start of the string.
`boolean` | `seek(java.lang.String stringToSeek)` Seek a string from the current cursor location.
`boolean` | `seekinsensitive(java.lang.String stringToSeek)` Seek a string from the current cursor location.
`void` | `set(int spot)` Set the cursor to the spot.
`void` | `start(java.lang.String stringToScan)` Start a scan.
`java.lang.String` | `substring(int numberCharacters)` Get a substring from the cursor for so many characters.
`java.lang.String` | `substringFromMark(int mark)` Like the standard substring, from the mark to the current cursor minus one.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### StringScanner

    public StringScanner()

Method Detail

### start

    public void start(java.lang.String stringToScan)
               throws ThingsException

  Start a scan. This must be done before any other methods are called.

  Parameters:
    `stringToScan` - The string to scan.
  Throws:
    `ThingsException` - if passed a null or empty string.

### reset

    public void reset()
               throws ThingsException

  Resets the cursor to the start of the string.

  Throws:
    `ThingsException` - if the scanner was not start()'d.

### seek

    public boolean seek(java.lang.String stringToSeek)
                 throws ThingsException

  Seek a string from the current cursor location. If it is found, the cursor will be set to the new location and the method will return true. Otherwise, it will return false. It is case sensitive.

  Parameters:
    `stringToSeek` - The string to seek.
  Returns:
    true if found, otherwise false.
  Throws:
    `ThingsException` - Only if the object was not start()'d.

### seekinsensitive

    public boolean seekinsensitive(java.lang.String stringToSeek)
                            throws ThingsException

  Seek a string from the current cursor location. If it is found, the cursor will be set to the new location and the method will return true. Otherwise, it will return false. It is not case sensitive and is definately slower.

  Parameters:
    `stringToSeek` - The string to seek.
  Returns:
    true if found, otherwise false.
  Throws:
    `ThingsException` - Only if the object was not start()'d.

### addpattern

    public void addpattern(java.lang.String patternName,
                           java.lang.String pattern)
                    throws ThingsException

  Adds a regex pattern to the scanner. It uses the java regex package.

  Parameters:
    `patternName` - The name of the pattern.
    `pattern` - The regular expression pattern.
  Throws:
    `ThingsException` - for any problems
  See Also:
    `Pattern`

### find

    public int find(java.lang.String patternName)
             throws ThingsException

  Find a pattern. return size of pattern, if found. zero if not found. cursor left at beginning. Cursor does not move if match fails.

  Parameters:
    `patternName` - The name of the pattern to find.
  Returns:
    The size of pattern, if found, or -1 if not found.
  Throws:
    `java.lang.Exception`
    `ThingsException`

### set

    public void set(int spot)
             throws ThingsException

  Set the cursor to the spot. If it is out of bounds, it will throw a ThingsException.

  Parameters:
    `spot` - The spot to set the cursor. If it is negative or past the end of the string, it will be out of bounds.
  Throws:
    `ThingsException`

### move

    public void move(int offset)
              throws ThingsException

  Move the cursor by an offset. If the new cursor is out of bounds, it will throw a ThingsException.

  Parameters:
    `offset` - The offset to change the cursor. It can be positive or negative.
  Throws:
    `ThingsException`

### get

    public int get()

  Get the cursor position

  Returns:
    the cursor position.

### getData

    public java.lang.String getData()

  Get the string being scanned. This is just a convenience.

  Returns:
    the string we are scanning.

### substring

    public java.lang.String substring(int numberCharacters)
                               throws ThingsException

  Get a substring from the cursor for so many characters. If the number of characters is too many, it'll throw a ThingsException.

  Parameters:
    `numberCharacters` - The number to get. Zero or negative will be ignored.
  Returns:
    The string.
  Throws:
    `ThingsException`

### substringFromMark

    public java.lang.String substringFromMark(int mark)
                                       throws ThingsException

  Like the standard substring, from the mark to the current cursor minus one.

  Parameters:
    `mark` - Mark point.
  Returns:
    The string.
  Throws:
    `ThingsException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Things.