org.pz.platypus.parsers
Class CommandParameterParser

java.lang.Object
  extended by org.pz.platypus.parsers.CommandParameterParser

public class CommandParameterParser
extends java.lang.Object

Handles all the various command-parameter parsing tasks. All public classes are static.


Constructor Summary
CommandParameterParser()
           
 
Method Summary
static int countBraces(char[] input, int start)
          Count the number of opening braces in a parameter
static java.lang.String extractNumericString(char[] content, int parsePoint)
          Extracts the numeric value from a specific point in a char array.
static java.lang.String extractStringInsideBraces(char[] input, int start)
          Extracts the string parameter enclosed in matching opening and closing braces
static CommandParameter extractStringParam(char[] input, int parsePoint)
          Static method that extracts a string parameter.
static UnitType extractUnitType(char[] input, int parsePoint)
          Gets the unit type.
static CommandParameter extractUnitValue(char[] input, int parsePoint)
          Parses a substring that contains a quantity.
static java.lang.String makeBraces(char braceChar, int howMany)
          Returns a string of braces (that is { or }, depending on the char passed to it) for the length specified.
static UnitType unitAbbrevToUnitType(char[] input, int parsePoint)
          Convert the abbreviation used for the unit into a unit-type (an enum in PlatyConst)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandParameterParser

public CommandParameterParser()
Method Detail

extractUnitValue

public static CommandParameter extractUnitValue(char[] input,
                                                int parsePoint)
Parses a substring that contains a quantity.

Parameters:
input - char[] that contains a numeric quantity
parsePoint - the point in input where the numeric quantity to isLineComment begins
Returns:
a CommandParameter instance containing value and type, or null on error

extractNumericString

public static java.lang.String extractNumericString(char[] content,
                                                    int parsePoint)
Extracts the numeric value from a specific point in a char array. Used for extracting the value of a parameter to a command

Parameters:
content - the char[] containing the value
parsePoint - where the value begins in content
Returns:
a string containing the value; or null if an error occurred.

extractUnitType

public static UnitType extractUnitType(char[] input,
                                       int parsePoint)
Gets the unit type. First it looks up any macro string, then converts the abbreviation for unit to a unit type

Parameters:
input - the characters that contain the unit type
parsePoint - where the unit type begins in input
Returns:
a UnitType, which will = UnitType.ERROR in the event of an error.

unitAbbrevToUnitType

public static UnitType unitAbbrevToUnitType(char[] input,
                                            int parsePoint)
Convert the abbreviation used for the unit into a unit-type (an enum in PlatyConst)

Parameters:
input - characters containing the unit abbreviation
parsePoint - where the unit abbreviation begins
Returns:
the UnitType enum that corresponds to the type or to an error

extractStringParam

public static CommandParameter extractStringParam(char[] input,
                                                  int parsePoint)
Static method that extracts a string parameter. This method accepts a parameter and checks it for matching initial/closing { } 's. Command parameters in Platypus that contain spaces are enclosed in { } characters. If the parameter should contain a {, then multiple { 's can be used to open and close the parameter. This function counts the number of opening {, builds a matching string of } 's and searches for it in the parameter; it then returns whatever it finds between these characters (trimmed of any white space. So: [ff:{times roman}] returns "times roman". Likewise {{{times roman}}} It then extracts the string between the matching { }. If there were no { }, it simply extracts the string.

Parameters:
input - the text we're parsing for the parameter
parsePoint - where the parameter begins
Returns:
a CommandParameter containing the string; or null in case of error

extractStringInsideBraces

public static java.lang.String extractStringInsideBraces(char[] input,
                                                         int start)
Extracts the string parameter enclosed in matching opening and closing braces

Parameters:
input - the text in which the braces and parameter are located
start - where the first opening brace begins
Returns:
the parameter, or an empty string on error

countBraces

public static int countBraces(char[] input,
                              int start)
Count the number of opening braces in a parameter

Parameters:
input - the chars containing the opening braces
start - where the opening braces start
Returns:
the number of opening braces.

makeBraces

public static java.lang.String makeBraces(char braceChar,
                                          int howMany)
Returns a string of braces (that is { or }, depending on the char passed to it) for the length specified. Invalid counts or brace-chars result in an empty string.

Parameters:
braceChar - is '{' for opening brace or '}' for closing brace
howMany - how many braces to put in the string
Returns:
the string containing the braces, or an empty string otherwise.


Copyright © 2008-10 Pacific Data Works LLC