Package tools
Class ParsingTools
Object
ParsingTools
public class ParsingTools
extends Object
The
ParsingTools class contains methods related to parsing user input, and is used heavily by parsing.-
Field Summary
Fields Modifier and Type Field Description static PatternnewlineMatches newlines with supported carriage returnsstatic PatternvalidNamesMatches all valid variable, function, and constant names -
Method Summary
Modifier and Type Method Description static chargetCharacter(String input)Converts the string to achar, supporting legitimate single-character strings like"x"and LaTeX-escaped characters like"\epsilon"static doublegetConstant(String infix)Evaluates infix corresponding to a constant, such aspi/3static booleanisAlmostInteger(double d)Checks if adoubleis within Settings.integerMargin of an integerstatic booleanparseBoolean(String s)Parses a string to a boolean using the following rules, ignoring case: TRUE:true, t, 1, yes, yFALSE:false, f, 0, no, nstatic StringprocessEscapes(String input)Returns the input string with LaTeX escapes removed (if they exist) ifSettings.removeEscapesis enabledstatic GeneralFunctiontoFunction(Object input)If the input is aGeneralFunction, returns the input.static inttoInteger(double d)
-
Field Details
-
newline
public static final Pattern newlineMatches newlines with supported carriage returns -
validNames
public static final Pattern validNamesMatches all valid variable, function, and constant names
-
-
Method Details
-
toFunction
If the input is aGeneralFunction, returns the input. If the input is aDouble, returns a newConstantof that value. If the input is aString, parses it withFunctionParser.parseInfix(String).- Parameters:
input- the input to be parsed as described above- Returns:
- the parsed input as described above
-
getConstant
public static double getConstant(String infix)Evaluates infix corresponding to a constant, such aspi/3- Parameters:
infix- the infix string of the constant- Returns:
- a
doublecorresponding to the evaluated constant to be evaluated
-
parseBoolean
public static boolean parseBoolean(String s)Parses a string to a boolean using the following rules, ignoring case: TRUE:true, t, 1, yes, yFALSE:false, f, 0, no, n- Parameters:
s- the string to be parsed- Returns:
- the string parsed to a boolean
-
toInteger
public static int toInteger(double d) throws IllegalArgumentException- Parameters:
d- thedoubleto be converted- Returns:
- the
doublerounded to an integer - Throws:
IllegalArgumentException- if thedoubleis not withinSettings.integerMarginof an integer
-
isAlmostInteger
public static boolean isAlmostInteger(double d) throws IllegalArgumentExceptionChecks if adoubleis within Settings.integerMargin of an integer- Parameters:
d- thedoubleto be checked- Returns:
- true if the
doubleis withinSettings.integerMarginof an integer - Throws:
IllegalArgumentException
-
getCharacter
public static char getCharacter(String input)Converts the string to achar, supporting legitimate single-character strings like"x"and LaTeX-escaped characters like"\epsilon"- Parameters:
input- the string containing the character- Returns:
- the character represented by the string
- Throws:
IllegalArgumentException- if the input is not in one of the formats specified above
-
processEscapes
public static String processEscapes(String input)Returns the input string with LaTeX escapes removed (if they exist) ifSettings.removeEscapesis enabled- Parameters:
input- the possibly-escaped string- Returns:
- the input with escapes processed
-