Parse a space delimited token. If quoted the token will consume all characters up to a matching quote, otherwise, it consumes up to the first delimiter character. @param quoted If true accept quoted strings.
(boolean quoted)
| 539 | * @param quoted If <strong>true</strong> accept quoted strings. |
| 540 | */ |
| 541 | String parseToken(boolean quoted) throws JasperException { |
| 542 | StringBuilder StringBuilder = new StringBuilder(); |
| 543 | skipSpaces(); |
| 544 | StringBuilder.setLength(0); |
| 545 | |
| 546 | if (!hasMoreInput()) { |
| 547 | return ""; |
| 548 | } |
| 549 | |
| 550 | int ch = peekChar(); |
| 551 | |
| 552 | if (quoted) { |
| 553 | if (ch == '"' || ch == '\'') { |
| 554 | |
| 555 | char endQuote = ch == '"' ? '"' : '\''; |
| 556 | // Consume the open quote: |
| 557 | ch = nextChar(); |
| 558 | for (ch = nextChar(); ch != -1 && ch != endQuote; ch = nextChar()) { |
| 559 | if (ch == '\\') { |
| 560 | ch = nextChar(); |
| 561 | } |
| 562 | StringBuilder.append((char) ch); |
| 563 | } |
| 564 | // Check end of quote, skip closing quote: |
| 565 | if (ch == -1) { |
| 566 | err.jspError(mark(), "jsp.error.quotes.unterminated"); |
| 567 | } |
| 568 | } else { |
| 569 | err.jspError(mark(), "jsp.error.attr.quoted"); |
| 570 | } |
| 571 | } else { |
| 572 | if (!isDelimiter()) { |
| 573 | // Read value until delimiter is found: |
| 574 | do { |
| 575 | ch = nextChar(); |
| 576 | // Take care of the quoting here. |
| 577 | if (ch == '\\') { |
| 578 | if (peekChar() == '"' || peekChar() == '\'' || peekChar() == '>' || peekChar() == '%') { |
| 579 | ch = nextChar(); |
| 580 | } |
| 581 | } |
| 582 | StringBuilder.append((char) ch); |
| 583 | } while (!isDelimiter()); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | return StringBuilder.toString(); |
| 588 | } |
| 589 | |
| 590 | |
| 591 | /** |
no test coverage detected