(Object reader, Object backslash, Object opts)
| 600 | |
| 601 | public static class CharacterReader extends AFn{ |
| 602 | public Object invoke(Object reader, Object backslash, Object opts) { |
| 603 | PushbackReader r = (PushbackReader) reader; |
| 604 | int ch = read1(r); |
| 605 | if(ch == -1) |
| 606 | throw Util.runtimeException("EOF while reading character"); |
| 607 | String token = readToken(r, (char) ch, false); |
| 608 | if(token.length() == 1) |
| 609 | return Character.valueOf(token.charAt(0)); |
| 610 | else if(token.equals("newline")) |
| 611 | return '\n'; |
| 612 | else if(token.equals("space")) |
| 613 | return ' '; |
| 614 | else if(token.equals("tab")) |
| 615 | return '\t'; |
| 616 | else if(token.equals("backspace")) |
| 617 | return '\b'; |
| 618 | else if(token.equals("formfeed")) |
| 619 | return '\f'; |
| 620 | else if(token.equals("return")) |
| 621 | return '\r'; |
| 622 | else if(token.startsWith("u")) |
| 623 | { |
| 624 | char c = (char) readUnicodeChar(token, 1, 4, 16); |
| 625 | if(c >= '\uD800' && c <= '\uDFFF') // surrogate code unit? |
| 626 | throw Util.runtimeException("Invalid character constant: \\u" + Integer.toString(c, 16)); |
| 627 | return c; |
| 628 | } |
| 629 | else if(token.startsWith("o")) |
| 630 | { |
| 631 | int len = token.length() - 1; |
| 632 | if(len > 3) |
| 633 | throw Util.runtimeException("Invalid octal escape sequence length: " + len); |
| 634 | int uc = readUnicodeChar(token, 1, len, 8); |
| 635 | if(uc > 0377) |
| 636 | throw Util.runtimeException("Octal escape sequence must be in range [0, 377]."); |
| 637 | return (char) uc; |
| 638 | } |
| 639 | throw Util.runtimeException("Unsupported character: \\" + token); |
| 640 | } |
| 641 | |
| 642 | } |
| 643 |
nothing calls this directly
no test coverage detected