(Object reader, Object backslash, Object opts, Object pendingForms)
| 1192 | |
| 1193 | public static class CharacterReader extends AFn{ |
| 1194 | public Object invoke(Object reader, Object backslash, Object opts, Object pendingForms) { |
| 1195 | PushbackReader r = (PushbackReader) reader; |
| 1196 | int ch = read1(r); |
| 1197 | if(ch == -1) |
| 1198 | throw Util.runtimeException("EOF while reading character"); |
| 1199 | String token = readToken(r, (char) ch); |
| 1200 | if(token.length() == 1) |
| 1201 | return Character.valueOf(token.charAt(0)); |
| 1202 | else if(token.equals("newline")) |
| 1203 | return '\n'; |
| 1204 | else if(token.equals("space")) |
| 1205 | return ' '; |
| 1206 | else if(token.equals("tab")) |
| 1207 | return '\t'; |
| 1208 | else if(token.equals("backspace")) |
| 1209 | return '\b'; |
| 1210 | else if(token.equals("formfeed")) |
| 1211 | return '\f'; |
| 1212 | else if(token.equals("return")) |
| 1213 | return '\r'; |
| 1214 | else if(token.startsWith("u")) |
| 1215 | { |
| 1216 | char c = (char) readUnicodeChar(token, 1, 4, 16); |
| 1217 | if(c >= '\uD800' && c <= '\uDFFF') // surrogate code unit? |
| 1218 | throw Util.runtimeException("Invalid character constant: \\u" + Integer.toString(c, 16)); |
| 1219 | return c; |
| 1220 | } |
| 1221 | else if(token.startsWith("o")) |
| 1222 | { |
| 1223 | int len = token.length() - 1; |
| 1224 | if(len > 3) |
| 1225 | throw Util.runtimeException("Invalid octal escape sequence length: " + len); |
| 1226 | int uc = readUnicodeChar(token, 1, len, 8); |
| 1227 | if(uc > 0377) |
| 1228 | throw Util.runtimeException("Octal escape sequence must be in range [0, 377]."); |
| 1229 | return (char) uc; |
| 1230 | } |
| 1231 | throw Util.runtimeException("Unsupported character: \\" + token); |
| 1232 | } |
| 1233 | |
| 1234 | } |
| 1235 |
nothing calls this directly
no test coverage detected