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 Pattern newline
    Matches newlines with supported carriage returns
    static Pattern validNames
    Matches all valid variable, function, and constant names
  • Method Summary

    Modifier and Type Method Description
    static char getCharacter​(String input)
    Converts the string to a char, supporting legitimate single-character strings like "x" and LaTeX-escaped characters like "\epsilon"
    static double getConstant​(String infix)
    Evaluates infix corresponding to a constant, such as pi/3
    static boolean isAlmostInteger​(double d)
    Checks if a double is within Settings.integerMargin of an integer
    static boolean parseBoolean​(String s)
    Parses a string to a boolean using the following rules, ignoring case: TRUE: true, t, 1, yes, y FALSE: false, f, 0, no, n
    static String processEscapes​(String input)
    Returns the input string with LaTeX escapes removed (if they exist) if Settings.removeEscapes is enabled
    static GeneralFunction toFunction​(Object input)
    If the input is a GeneralFunction, returns the input.
    static int toInteger​(double d)
    Converts a double within Settings.integerMargin of an integer to an int

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • newline

      public static final Pattern newline
      Matches newlines with supported carriage returns
    • validNames

      public static final Pattern validNames
      Matches all valid variable, function, and constant names
  • Method Details

    • toFunction

      public static GeneralFunction toFunction​(Object input)
      If the input is a GeneralFunction, returns the input. If the input is a Double, returns a new Constant of that value. If the input is a String, parses it with FunctionParser.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 as pi/3
      Parameters:
      infix - the infix string of the constant
      Returns:
      a double corresponding 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, y FALSE: 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
      Converts a double within Settings.integerMargin of an integer to an int
      Parameters:
      d - the double to be converted
      Returns:
      the double rounded to an integer
      Throws:
      IllegalArgumentException - if the double is not within Settings.integerMargin of an integer
    • isAlmostInteger

      public static boolean isAlmostInteger​(double d) throws IllegalArgumentException
      Checks if a double is within Settings.integerMargin of an integer
      Parameters:
      d - the double to be checked
      Returns:
      true if the double is within Settings.integerMargin of an integer
      Throws:
      IllegalArgumentException
    • getCharacter

      public static char getCharacter​(String input)
      Converts the string to a char, 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) if Settings.removeEscapes is enabled
      Parameters:
      input - the possibly-escaped string
      Returns:
      the input with escapes processed