(Object reader, Object doublequote, Object opts)
| 404 | |
| 405 | public static class StringReader extends AFn{ |
| 406 | public Object invoke(Object reader, Object doublequote, Object opts) { |
| 407 | StringBuilder sb = new StringBuilder(); |
| 408 | Reader r = (Reader) reader; |
| 409 | |
| 410 | for(int ch = read1(r); ch != '"'; ch = read1(r)) |
| 411 | { |
| 412 | if(ch == -1) |
| 413 | throw Util.runtimeException("EOF while reading string"); |
| 414 | if(ch == '\\') //escape |
| 415 | { |
| 416 | ch = read1(r); |
| 417 | if(ch == -1) |
| 418 | throw Util.runtimeException("EOF while reading string"); |
| 419 | switch(ch) |
| 420 | { |
| 421 | case 't': |
| 422 | ch = '\t'; |
| 423 | break; |
| 424 | case 'r': |
| 425 | ch = '\r'; |
| 426 | break; |
| 427 | case 'n': |
| 428 | ch = '\n'; |
| 429 | break; |
| 430 | case '\\': |
| 431 | break; |
| 432 | case '"': |
| 433 | break; |
| 434 | case 'b': |
| 435 | ch = '\b'; |
| 436 | break; |
| 437 | case 'f': |
| 438 | ch = '\f'; |
| 439 | break; |
| 440 | case 'u': |
| 441 | { |
| 442 | ch = read1(r); |
| 443 | if (Character.digit(ch, 16) == -1) |
| 444 | throw Util.runtimeException("Invalid unicode escape: \\u" + (char) ch); |
| 445 | ch = readUnicodeChar((PushbackReader) r, ch, 16, 4, true); |
| 446 | break; |
| 447 | } |
| 448 | default: |
| 449 | { |
| 450 | if(Character.isDigit(ch)) |
| 451 | { |
| 452 | ch = readUnicodeChar((PushbackReader) r, ch, 8, 3, false); |
| 453 | if(ch > 0377) |
| 454 | throw Util.runtimeException("Octal escape sequence must be in range [0, 377]."); |
| 455 | } |
| 456 | else |
| 457 | throw Util.runtimeException("Unsupported escape character: \\" + (char) ch); |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | sb.append((char) ch); |
| 462 | } |
| 463 | return sb.toString(); |
nothing calls this directly
no test coverage detected