org.jtr.transliterate
Class CharacterParser

java.lang.Object
  |
  +--org.jtr.transliterate.CharacterParser

public final class CharacterParser
extends java.lang.Object

Simple parser for characters and character ranges.

Usage:

Either:

  1. Use the CharacterReplacer constructors with String arguments for the search and replacement lists—these will call this class as necessary, or
  2. Call this class directly to create the CharacterList classes required for your pattern matches, then pass these on to a CharacterReplacer constructor. This allows CharacterList objects to be cached if desired.

Note:

CharacterParser objects are not thread safe. If thread safety is required, either externally synchronize any calls to a CharacterParser instance, or create new instances as required for each thread.

Version:
$Id: CharacterParser.java,v 1.12 2005/03/14 04:31:58 run2000 Exp $
Author:
Nicholas Cull

Field Summary
static int COMPLEMENT_MASK
          Complement the search list.
static int DELETE_UNREPLACEABLES_MASK
          Delete any characters in the search list that don't have a corresponding character in the replacement list.
static int SQUASH_DUPLICATES_MASK
          Squash any replacement characters that occur more than once in succession during the transliteration process.
 
Constructor Summary
CharacterParser()
          Creates new CharacterParser
 
Method Summary
 CharacterList compilePattern(char[] aPattern)
          The main compile routine, using a character array as the pattern to be compiled.
 CharacterList compilePattern(java.lang.String aPattern)
          The main compile routine, using a String as the pattern to be compiled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COMPLEMENT_MASK

public static final int COMPLEMENT_MASK
Complement the search list. With this flag set, any character that does not appear in the search list will be matched.

DELETE_UNREPLACEABLES_MASK

public static final int DELETE_UNREPLACEABLES_MASK
Delete any characters in the search list that don't have a corresponding character in the replacement list. By default, if the replacement list is too short, duplicate the last character until the replacement list is long enough.

SQUASH_DUPLICATES_MASK

public static final int SQUASH_DUPLICATES_MASK
Squash any replacement characters that occur more than once in succession during the transliteration process. By default, duplicate replacements are retained.
Constructor Detail

CharacterParser

public CharacterParser()
Creates new CharacterParser
Method Detail

compilePattern

public CharacterList compilePattern(java.lang.String aPattern)
                             throws CharacterParseException
The main compile routine, using a String as the pattern to be compiled.
Parameters:
aPattern - the pattern to be compiled by the compiler
Returns:
a CharacterList object containing the compiled pattern
Throws:
CharacterParseException - something went wrong during the parse of the pattern
NullPointerException - aPattern is null

compilePattern

public CharacterList compilePattern(char[] aPattern)
                             throws CharacterParseException

The main compile routine, using a character array as the pattern to be compiled. The method performs a one character lookahead, to determine when it sees a character range, and whether it is a real range, or just a lone hyphen.

Parameters:
aPattern - the pattern to be compiled by the compiler
Returns:
a CharacterList object containing the compiled pattern
Throws:
CharacterParseException - something went wrong during the parse of the pattern
NullPointerException - aPattern is null