Class JsopTokenizer

  • All Implemented Interfaces:
    JsopReader

    public class JsopTokenizer
    extends java.lang.Object
    implements JsopReader
    A tokenizer for Json and Jsop strings.
    • Constructor Summary

      Constructors 
      Constructor Description
      JsopTokenizer​(java.lang.String json)  
      JsopTokenizer​(java.lang.String json, int pos)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String decode​(java.lang.String s)
      Decode a Json string.
      static java.lang.String decodeQuoted​(java.lang.String s)
      Decode a quoted Json string.
      java.lang.String getEscapedToken()
      Get the last encoded (raw) string, including escape sequences.
      int getLastPos()  
      int getPos()  
      java.lang.String getToken()
      Get the last token value if the the token type was STRING or NUMBER.
      int getTokenType()
      Get the token type of the last token.
      boolean matches​(int type)
      Read a token which must match a given token type.
      int read()
      Read a token and return the token type.
      java.lang.String read​(int type)
      Read a token which must match a given token type.
      java.lang.String readRawValue()
      Read a value and return the raw Json representation.
      java.lang.String readString()
      Read a string.
      void resetReader()
      Reset the position to 0, so that to restart reading.
      void setPos​(int pos)  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • JsopTokenizer

        public JsopTokenizer​(java.lang.String json,
                             int pos)
      • JsopTokenizer

        public JsopTokenizer​(java.lang.String json)
    • Method Detail

      • resetReader

        public void resetReader()
        Description copied from interface: JsopReader
        Reset the position to 0, so that to restart reading.
        Specified by:
        resetReader in interface JsopReader
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getTokenType

        public int getTokenType()
        Get the token type of the last token.
        Specified by:
        getTokenType in interface JsopReader
        Returns:
        the token type
      • getToken

        public java.lang.String getToken()
        Get the last token value if the the token type was STRING or NUMBER. For STRING, the text is decoded; for NUMBER, it is returned as parsed. In all other cases the result is undefined.
        Specified by:
        getToken in interface JsopReader
        Returns:
        the token
      • getEscapedToken

        public java.lang.String getEscapedToken()
        Get the last encoded (raw) string, including escape sequences.
        Returns:
        the encoded string
      • read

        public java.lang.String read​(int type)
        Read a token which must match a given token type.
        Specified by:
        read in interface JsopReader
        Parameters:
        type - the token type
        Returns:
        the token (a null object when reading a null value)
        Throws:
        java.lang.IllegalStateException - if the token type doesn't match
      • readString

        public java.lang.String readString()
        Read a string.
        Specified by:
        readString in interface JsopReader
        Returns:
        the de-escaped string
        Throws:
        java.lang.IllegalStateException - if the token type doesn't match
      • matches

        public boolean matches​(int type)
        Read a token which must match a given token type.
        Specified by:
        matches in interface JsopReader
        Parameters:
        type - the token type
        Returns:
        true if there was a match
      • read

        public int read()
        Read a token and return the token type.
        Specified by:
        read in interface JsopReader
        Returns:
        the token type
      • decodeQuoted

        public static java.lang.String decodeQuoted​(java.lang.String s)
        Decode a quoted Json string.
        Parameters:
        s - the encoded string, with double quotes
        Returns:
        the string
      • decode

        public static java.lang.String decode​(java.lang.String s)
        Decode a Json string.
        Parameters:
        s - the encoded string, without double quotes
        Returns:
        the string
      • readRawValue

        public java.lang.String readRawValue()
        Read a value and return the raw Json representation. This includes arrays and nested arrays.
        Specified by:
        readRawValue in interface JsopReader
        Returns:
        the Json representation of the value
      • getPos

        public int getPos()
      • getLastPos

        public int getLastPos()
      • setPos

        public void setPos​(int pos)