org.jtr.transliterate
Class Perl5Parser

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

public final class Perl5Parser
extends java.lang.Object

A utility class for providing Perl 5 syntactic sugar on top of the CharacterParser class. This parses Perl-style transliteration strings into a form suitable for CharacterParser. For instance, the string "tr/a-zA-Z/0-9a-zA-Z/cd" is parsed into two strings "a-zA-Z", "0-9a-zA-Z", and the flags COMPLEMENT_MASK | DELETE_UNREPLACEABLES_MASK.

Since:
1.1
Version:
$Id: Perl5Parser.java,v 1.3 2005/03/14 06:40:18 run2000 Exp $
Author:
Nicholas Cull

Method Summary
static void main(java.lang.String[] args)
          A simple test case for this class.
static CharacterReplacer makeReplacer(java.lang.String source)
          Parses the given string in Perl syntax and returns a populated CharacterReplacer object that can be used to perform the specified transliteration.
static int parsePerlString(java.lang.String source, java.lang.StringBuffer input, java.lang.StringBuffer output)
          Parses the given Perl-style transliteration string into two parts:
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeReplacer

public static CharacterReplacer makeReplacer(java.lang.String source)
                                      throws CharacterParseException

Parses the given string in Perl syntax and returns a populated CharacterReplacer object that can be used to perform the specified transliteration.

This is a simple factory method that calls the parsePerlString method below, creates a new CharacterReplacer object and populates it with the results.

Parameters:
source - the String to be parsed and compiled
Returns:
a new CharacterReplacer ready for transliterations
Throws:
CharacterParseException - something went wrong during parsing
NullPointerException - source is null

parsePerlString

public static int parsePerlString(java.lang.String source,
                                  java.lang.StringBuffer input,
                                  java.lang.StringBuffer output)
                           throws CharacterParseException

Parses the given Perl-style transliteration string into two parts:

  1. The input character string to be transliterated
  2. The replacement character string

These strings can then be fed into the constructors for CharacterReplacer. It also returns any flags encountered at the end of the string into a form suitable for CharacterReplacer.

Parameters:
source - the string to be parsed
input - (out) the characters to be transliterated
output - (out) the replacement characters
Returns:
any flags parsed at the end of the character sequence
Throws:
CharacterParseException - there was a problem parsing the source String
NullPointerException - source is null

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
A simple test case for this class.
Parameters:
args - ignored
Throws:
java.lang.Exception - if an exception is encountered, throw it to the caller