Escape the given char. @param c the char @return a char array with the escaped sequence
(char c)
| 30 | * @return a char array with the escaped sequence |
| 31 | */ |
| 32 | public static char[] escape(char c) { |
| 33 | if (c < 0x20 || c == 0x22 || c == 0x5c || Character.isHighSurrogate(c) || Character.isLowSurrogate(c)) { |
| 34 | char popular = getPopularChar(c); |
| 35 | if (popular > 0) { |
| 36 | return new char[] { '\\', popular }; |
| 37 | } else { |
| 38 | StringBuilder escaped = new StringBuilder(6); |
| 39 | escaped.append("\\u"); |
| 40 | escaped.append(String.format("%04X", Integer.valueOf(c))); |
| 41 | return escaped.toString().toCharArray(); |
| 42 | } |
| 43 | } else { |
| 44 | char[] result = new char[1]; |
| 45 | result[0] = c; |
| 46 | return result; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Escape the given string. |