public class JSONFunctions extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
ILLEGAL_CHAR |
static String |
ILLEGAL_ESCAPE_SEQUENCE |
static String |
ILLEGAL_UNICODE_SEQUENCE |
static String |
UNTERMINATED_STRING |
| Constructor and Description |
|---|
JSONFunctions() |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendChar(Appendable a,
char ch,
boolean includeNonASCII)
Append a single character to an
Appendable applying JSON escaping rules. |
static void |
appendDisplayString(Appendable a,
String str,
int maxChars)
Append a display form of a string to an
Appendable, usually for error reporting. |
static void |
appendString(Appendable a,
CharSequence cs,
boolean includeNonASCII)
Append a
CharSequence to an Appendable in JSON quoted string form (applying JSON escaping rules). |
static String |
displayString(String str,
int maxChars)
Create a display form of a string, usually for error reporting.
|
static String |
escapeString(CharSequence cs,
boolean includeNonASCII)
Convert a
CharSequence to a String in JSON quoted string form (applying JSON escaping rules). |
static String |
escapeStringUnquoted(CharSequence cs)
Convert a
CharSequence to a String, applying JSON escaping rules without enclosing quotes. |
static String |
escapeStringUnquoted(CharSequence cs,
boolean includeNonASCII)
Convert a
CharSequence to a String, applying JSON escaping rules without enclosing quotes. |
static boolean |
isSpaceCharacter(char ch)
Test whether a given character is a space, according to the JSON specification.
|
static void |
outputChar(char ch,
boolean includeNonASCII,
IntConsumer consumer)
Output a single character using an
IntConsumer applying JSON escaping rules. |
static void |
outputString(CharSequence cs,
boolean includeNonASCII,
IntConsumer consumer)
Output a
CharSequence using an IntConsumer in JSON quoted string form (applying JSON escaping
rules). |
static String |
parseString(io.jstuff.text.TextMatcher tm)
Parse a JSON string from the current position of a
TextMatcher (which must be positioned after the
opening double quote). |
public static final String UNTERMINATED_STRING
public static final String ILLEGAL_CHAR
public static final String ILLEGAL_UNICODE_SEQUENCE
public static final String ILLEGAL_ESCAPE_SEQUENCE
public static void appendString(Appendable a, CharSequence cs, boolean includeNonASCII) throws IOException
CharSequence to an Appendable in JSON quoted string form (applying JSON escaping rules).
The characters above the ASCII range (0x20 to 0x7E) are output as Unicode escape sequences unless
the includeNonASCII flag is set to true.a - the Appendablecs - the CharSequenceincludeNonASCII - if true, output the characters above the ASCII range without escapingIOException - if thrown by the Appendablepublic static void outputString(CharSequence cs, boolean includeNonASCII, IntConsumer consumer)
CharSequence using an IntConsumer in JSON quoted string form (applying JSON escaping
rules). The characters above the ASCII range (0x20 to 0x7E) are output as Unicode escape
sequences unless the includeNonASCII flag is set to true.cs - the CharSequenceincludeNonASCII - if true, output the characters above the ASCII range without escapingconsumer - the IntConsumerpublic static String escapeString(CharSequence cs, boolean includeNonASCII)
CharSequence to a String in JSON quoted string form (applying JSON escaping rules).
The characters above the ASCII range (0x20 to 0x7E) are output as Unicode escape sequences unless
the includeNonASCII flag is set to true.cs - the CharSequenceincludeNonASCII - if true, output the characters above the ASCII range without escapingpublic static String escapeStringUnquoted(CharSequence cs, boolean includeNonASCII)
CharSequence to a String, applying JSON escaping rules without enclosing quotes. The
characters above the ASCII range (0x20 to 0x7E) are output as Unicode escape sequences unless the
includeNonASCII flag is set to true. If there are no characters requiring conversion, the
original string is returned unmodified.cs - the CharSequenceincludeNonASCII - if true, output the characters above the ASCII range without escapingpublic static String escapeStringUnquoted(CharSequence cs)
CharSequence to a String, applying JSON escaping rules without enclosing quotes. If
there are no characters requiring conversion, the original string is returned unmodified.cs - the CharSequencepublic static void appendChar(Appendable a, char ch, boolean includeNonASCII) throws IOException
Appendable applying JSON escaping rules. The characters above the ASCII
range (0x20 to 0x7E) are output as Unicode escape sequences unless the includeNonASCII
flag is set to true.a - the Appendablech - the characterincludeNonASCII - if true, output the characters above the ASCII range without escapingIOException - if thrown by the Appendablepublic static void outputChar(char ch,
boolean includeNonASCII,
IntConsumer consumer)
IntConsumer applying JSON escaping rules. The characters above the
ASCII range (0x20 to 0x7E) are output as Unicode escape sequences unless the
includeNonASCII flag is set to true.ch - the characterincludeNonASCII - if true, output the characters above the ASCII range without escapingconsumer - the IntConsumerpublic static String displayString(String str, int maxChars)
... " is inserted in the middle
(because the inserted string is 5 characters long, the elided string will look better if an odd number is chosen
for the maximum length, since that will result in equal length substrings at start and end).str - the stringmaxChars - the maximum number of characters (ignored if < 8)public static void appendDisplayString(Appendable a, String str, int maxChars) throws IOException
Appendable, usually for error reporting. The string is
constrained to a maximum number of characters, and if it exceeds that number the string is split and
" ... " is inserted in the middle (because the inserted string is 5 characters long, the elided
string will look better if an odd number is chosen for the maximum length, since that will result in equal length
substrings at start and end).a - the Appendablestr - the stringmaxChars - the maximum number of characters (ignored if < 8)IOExceptionpublic static String parseString(io.jstuff.text.TextMatcher tm)
TextMatcher (which must be positioned after the
opening double quote). The index is left positioned after the closing double quote.tm - a TextMatcherIllegalArgumentException - if there are any errors in the JSONpublic static boolean isSpaceCharacter(char ch)
ch - the charactertrue if the character is a spaceCopyright © 2025. All rights reserved.