@param s the input string - must not be null @return escaped string, per Java rule
(String s)
| 126 | * @return escaped string, per Java rule |
| 127 | */ |
| 128 | static String escape(String s) { |
| 129 | |
| 130 | StringBuilder b = new StringBuilder(); |
| 131 | for (int i = 0; i < s.length(); i++) { |
| 132 | char c = s.charAt(i); |
| 133 | if (c == '"') { |
| 134 | b.append('\\').append('"'); |
| 135 | } else if (c == '\\') { |
| 136 | b.append('\\').append('\\'); |
| 137 | } else if (c == '\n') { |
| 138 | b.append('\\').append('n'); |
| 139 | } else if (c == '\r') { |
| 140 | b.append('\\').append('r'); |
| 141 | } else { |
| 142 | b.append(c); |
| 143 | } |
| 144 | } |
| 145 | return b.toString(); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Single quote and escape a character |