Package org.cthing.escapers
Class JsonEscaper
java.lang.Object
org.cthing.escapers.JsonEscaper
Escapes strings and character arrays according to the
JSON specification. Characters are escaped
according to the following table:
| Character | Escape | Description |
|---|---|---|
| 0x00 - 0x07 | \uXXXX | ASCII control characters |
| 0x08 | \b | Backspace |
| 0x09 | \t | Tab |
| 0x0A | \n | Line feed |
| 0x0B | \uXXXX | ASCII control character |
| 0x0C | \f | Form feed |
| 0x0D | \r | Carriage return |
| 0x0E - 0x1F | \uXXXX | ASCII control characters |
| 0x20 - 0x21 | Unchanged | Printable ASCII characters |
| 0x22 | \" | Double quote |
| 0x23 - 0x2E | Unchanged | Printable ASCII characters |
| 0x2F | \/ | Forward slash |
| 0x30 - 0x5B | Unchanged | Printable ASCII characters |
| 0x5C | \\ | Backslash |
| 0x5D - 0x7E | Unchanged | Printable ASCII characters |
| 0x7F | \uXXXX | ASCII control character |
| 0x80 - 0x10FFFF | Unchanged by default or \uXXXX[\uXXXX] if JsonEscaper.Option.ESCAPE_NON_ASCII specified |
ISO Latin-1, Unicode BMP and surrogate pairs |
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidescape(char[] charArr, int offset, int length, Writer writer, Set<JsonEscaper.Option> options) Applies JSON escaping to the specified character array and writes the result to the specified writer.static voidescape(char[] charArr, int offset, int length, Writer writer, JsonEscaper.Option... options) Applies JSON escaping to the specified character array and writes the result to the specified writer.static Stringescape(char[] charArr, int offset, int length, Set<JsonEscaper.Option> options) Applies JSON escaping to the specified character array.static Stringescape(char[] charArr, int offset, int length, JsonEscaper.Option... options) Applies JSON escaping to the specified character array.static voidescape(char[] charArr, Writer writer, Set<JsonEscaper.Option> options) Applies JSON escaping to the specified character array and writes the result to the specified writer.static voidescape(char[] charArr, Writer writer, JsonEscaper.Option... options) Applies JSON escaping to the specified character array and writes the result to the specified writer.static Stringescape(char[] charArr, Set<JsonEscaper.Option> options) Applies JSON escaping to the specified character array.static Stringescape(char[] charArr, JsonEscaper.Option... options) Applies JSON escaping to the specified character array.static voidescape(CharSequence charSequence, Writer writer, Set<JsonEscaper.Option> options) Applies JSON escaping to the specified string and writes the result to the specified writer.static voidescape(CharSequence charSequence, Writer writer, JsonEscaper.Option... options) Applies JSON escaping to the specified string and writes the result to the specified writer.static Stringescape(CharSequence charSequence, Set<JsonEscaper.Option> options) Applies JSON escaping to the specified string.static Stringescape(CharSequence charSequence, JsonEscaper.Option... options) Applies JSON escaping to the specified string.
-
Method Details
-
escape
Applies JSON escaping to the specified string.- Parameters:
charSequence- String to escapeoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
Applies JSON escaping to the specified string.- Parameters:
charSequence- String to escapeoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
@WillNotClose public static void escape(CharSequence charSequence, Writer writer, JsonEscaper.Option... options) throws IOException Applies JSON escaping to the specified string and writes the result to the specified writer.- Parameters:
charSequence- String to escapewriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(CharSequence charSequence, Writer writer, Set<JsonEscaper.Option> options) throws IOException Applies JSON escaping to the specified string and writes the result to the specified writer.- Parameters:
charSequence- String to escapewriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
Applies JSON escaping to the specified character array.- Parameters:
charArr- Character array to escapeoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
Applies JSON escaping to the specified character array.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arrayoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
Applies JSON escaping to the specified character array.- Parameters:
charArr- Character array to escapeoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
public static String escape(char[] charArr, int offset, int length, Set<JsonEscaper.Option> options) Applies JSON escaping to the specified character array.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arrayoptions- Escaping options- Returns:
- Escaped string or
nullifnullwas passed in.
-
escape
@WillNotClose public static void escape(char[] charArr, Writer writer, JsonEscaper.Option... options) throws IOException Applies JSON escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapewriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(char[] charArr, int offset, int length, Writer writer, JsonEscaper.Option... options) throws IOException Applies JSON escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arraywriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(char[] charArr, Writer writer, Set<JsonEscaper.Option> options) throws IOException Applies JSON escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapewriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-
escape
@WillNotClose public static void escape(char[] charArr, int offset, int length, Writer writer, Set<JsonEscaper.Option> options) throws IOException Applies JSON escaping to the specified character array and writes the result to the specified writer.- Parameters:
charArr- Character array to escapeoffset- Start index in arraylength- Number of characters in arraywriter- Writer to which the escaped string is writtenoptions- Escaping options- Throws:
IOException- if there was a problem writing the escaped stringIllegalArgumentException- if the writer isnull
-