Package org.cthing.escapers
Class JavaEscaper
java.lang.Object
org.cthing.escapers.JavaEscaper
Escapes strings and character arrays according to the
Escape Sequences
section of the Java Language 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 | Unchanged or \s if JavaEscaper.Option.ESCAPE_SPACE specified |
Space character |
| 0x21 | Unchanged | Printable ASCII characters |
| 0x22 | \" | Double quote |
| 0x23 - 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 JavaEscaper.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<JavaEscaper.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, JavaEscaper.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<JavaEscaper.Option> options) Applies JSON escaping to the specified character array.static Stringescape(char[] charArr, int offset, int length, JavaEscaper.Option... options) Applies JSON escaping to the specified character array.static voidescape(char[] charArr, Writer writer, Set<JavaEscaper.Option> options) Applies JSON escaping to the specified character array and writes the result to the specified writer.static voidescape(char[] charArr, Writer writer, JavaEscaper.Option... options) Applies JSON escaping to the specified character array and writes the result to the specified writer.static Stringescape(char[] charArr, Set<JavaEscaper.Option> options) Applies JSON escaping to the specified character array.static Stringescape(char[] charArr, JavaEscaper.Option... options) Applies JSON escaping to the specified character array.static voidescape(CharSequence charSequence, Writer writer, Set<JavaEscaper.Option> options) Applies JSON escaping to the specified string and writes the result to the specified writer.static voidescape(CharSequence charSequence, Writer writer, JavaEscaper.Option... options) Applies JSON escaping to the specified string and writes the result to the specified writer.static Stringescape(CharSequence charSequence, Set<JavaEscaper.Option> options) Applies JSON escaping to the specified string.static Stringescape(CharSequence charSequence, JavaEscaper.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, JavaEscaper.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<JavaEscaper.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<JavaEscaper.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, JavaEscaper.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, JavaEscaper.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<JavaEscaper.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<JavaEscaper.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
-