Class TextReader


  • public class TextReader
    extends Object
    Read through text string
    Author:
    osbornb
    • Constructor Detail

      • TextReader

        public TextReader​(String text)
        Constructor
        Parameters:
        text - text
      • TextReader

        public TextReader​(Reader reader)
        Constructor
        Parameters:
        reader - reader
      • TextReader

        public TextReader​(String text,
                          boolean includeQuotes)
        Constructor
        Parameters:
        text - text
        includeQuotes - include quotes
      • TextReader

        public TextReader​(Reader reader,
                          boolean includeQuotes)
        Constructor
        Parameters:
        reader - reader
        includeQuotes - include quotes
    • Method Detail

      • getReader

        public Reader getReader()
        Get the reader
        Returns:
        reader
      • isIncludeQuotes

        public boolean isIncludeQuotes()
        Is include quotes enabled
        Returns:
        include quotes setting
      • setIncludeQuotes

        public void setIncludeQuotes​(boolean includeQuotes)
        Set the include quotes setting
        Parameters:
        includeQuotes - true to include quotes
      • close

        public void close()
        Close the text reader
      • readToken

        public String readToken()
                         throws IOException
        Read the next token. Ignores whitespace until a non whitespace character is encountered. Returns a contiguous block of token characters ( [a-z] | [A-Z] | [0-9] | - | . | + | : | _ ) or a non whitespace single character.
        Returns:
        token
        Throws:
        IOException - upon read error
      • peekToken

        public String peekToken()
                         throws IOException
        Peek at the next token without reading past it
        Returns:
        next token
        Throws:
        IOException - upon read error
      • peekToken

        public String peekToken​(int num)
                         throws IOException
        Peek at a token without reading past it
        Parameters:
        num - number of tokens out to peek at
        Returns:
        token
        Throws:
        IOException - upon read error
      • pushToken

        public void pushToken​(String token)
        Push a token back onto the read cache
        Parameters:
        token - token
      • readExpectedToken

        public String readExpectedToken()
                                 throws IOException
        Read an expected token
        Returns:
        token
        Throws:
        IOException - upon read error
      • peekExpectedToken

        public String peekExpectedToken()
                                 throws IOException
        Peek at the next expected token without reading past it
        Returns:
        next token
        Throws:
        IOException - upon read error
      • peekExpectedToken

        public String peekExpectedToken​(int num)
                                 throws IOException
        Peek at the next expected token without reading past it
        Parameters:
        num - number of tokens out to peek at
        Returns:
        token
        Throws:
        IOException - upon read error
      • readNumber

        public double readNumber()
                          throws IOException
        Read a signed number as a double
        Returns:
        signed double
        Throws:
        IOException - upon failure to read
      • readUnsignedNumber

        public double readUnsignedNumber()
                                  throws IOException
        Read an unsigned number as a double
        Returns:
        unsigned double
        Throws:
        IOException - upon failure to read
      • readInteger

        public int readInteger()
                        throws IOException
        Read a signed integer
        Returns:
        signed integer
        Throws:
        IOException - upon failure to read
      • readUnsignedInteger

        public int readUnsignedInteger()
                                throws IOException
        Read an unsigned integer
        Returns:
        unsigned integer
        Throws:
        IOException - upon failure to read
      • isTokenCharacter

        public static boolean isTokenCharacter​(char c)
        Check if the character is a contiguous block token character: ( [a-z] | [A-Z] | [0-9] | - | . | + | : | _ )
        Parameters:
        c - character
        Returns:
        true if token character
        Since:
        1.1.3
      • isQuoteCharacter

        public static boolean isQuoteCharacter​(char c)
        Check if the character is a quote character
        Parameters:
        c - character
        Returns:
        true if quote character
        Since:
        1.1.3
      • isWhitespace

        public static boolean isWhitespace​(char c)
        Check if the character is whitespace or a space character
        Parameters:
        c - character
        Returns:
        true if whitespace
        Since:
        1.1.3