public final class JSONString extends Object implements CharSequence, Comparable<JSONString>, Iterable<Character>
This is a class that parses and encodes JSONStrings.
All methods inherited by CharSequence
act on the parsed version
of the string.
Modifier and Type | Class and Description |
---|---|
protected static class |
JSONString.ParseAdapter
an implementation of Parselistener that does nothing
|
protected static interface |
JSONString.ParseListener
This is a listener used by
parse(ParseListener) to
notify about interesting events. |
Modifier | Constructor and Description |
---|---|
protected |
JSONString(CharSequence unparsedString)
Creates a JSONString from the specified unparsedString
|
Modifier and Type | Method and Description |
---|---|
char |
charAt(int index) |
protected JSONString |
clone() |
int |
compareTo(JSONString other) |
protected static CharSequence |
encode(CharSequence s)
This is the inverse of parse.
|
boolean |
equals(Object other) |
static JSONString |
generateParsed(CharSequence c)
Constructs a JSONString that is equivalent to the given CharSequence.
|
static JSONString |
generateUnparsed(CharSequence c)
This generates a JSONString from a raw CharSequence.
|
protected static Map<Character,Character> |
getCharactersToEscape()
returns the map of character it represents to the escape characters.
|
protected static Map<Character,Character> |
getEscapeToCharacters()
returns the map of escape characters to the character it represents.
|
String |
getUnparsedString()
returns the unparsed version of this string
|
int |
hashCode() |
static boolean |
isValid(CharSequence unparsed)
Determines if the string is a valid string
|
Iterator<Character> |
iterator() |
int |
length() |
protected void |
parse(JSONString.ParseListener l)
Parses the string contained in this
|
protected static void |
parse(JSONString.ParseListener l,
CharSequence string)
Parses the specified string
|
CharSequence |
subSequence(int start,
int length) |
String |
toString() |
protected JSONString(CharSequence unparsedString) throws ParseException
unparsedString
- the string to build this fromParseException
- if the string is malformed.public static final JSONString generateParsed(CharSequence c)
0<i<c.length()
,
generateParsed(c).charAt(i) == c.charAt(i)
c
- the CharSequence to copypublic static final JSONString generateUnparsed(CharSequence c) throws ParseException
c
- the CharSequence to parseParseException
- if c is not a properly formed JSON string.public char charAt(int index) throws IndexOutOfBoundsException
charAt
in interface CharSequence
IndexOutOfBoundsException
public int length()
length
in interface CharSequence
public CharSequence subSequence(int start, int length)
subSequence
in interface CharSequence
public int compareTo(JSONString other)
compareTo
in interface Comparable<JSONString>
public static boolean isValid(CharSequence unparsed)
unparsed
- public String getUnparsedString()
public String toString()
toString
in interface CharSequence
toString
in class Object
protected static void parse(JSONString.ParseListener l, CharSequence string) throws ParseException, NullPointerException
l
- the listener that is told what to do upon interesting eventsstring
- the string to parseParseException
- if an exception occurs parsing the stringNullPointerException
- if the listener is nullprotected void parse(JSONString.ParseListener l) throws ParseException, NullPointerException
l
- the listener that is told what to do upon interesting eventsParseException
- if an exception occurs parsing the stringNullPointerException
- if the listener is nullprotected static CharSequence encode(CharSequence s)
s
- the CharSequence to encodeprotected static Map<Character,Character> getCharactersToEscape()
protected static Map<Character,Character> getEscapeToCharacters()
protected JSONString clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException