| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -639,25 +639,48 @@ public String format(final String source) { | |||
| 639 | 639 | break; | |
| 640 | 640 | ||
| 641 | 641 | case '"': | |
| 642 | + case '“': | ||
| 643 | + case '”': | ||
| 642 | 644 | case '\'': | |
| 645 | + case '‘': | ||
| 646 | + case '’': | ||
| 643 | 647 | inStatementFlag = true; | |
| 644 | - buf.append(c); | ||
| 648 | + char realQuote = c; | ||
| 649 | + if (c == '“' || c == '”') realQuote = '"'; | ||
| 650 | + if (c == '‘' || c == '’') realQuote = '\''; | ||
| 651 | + buf.append(realQuote); | ||
| 652 | + | ||
| 653 | + char otherQuote = c; | ||
| 654 | + if (c == '“') otherQuote = '”'; | ||
| 655 | + if (c == '”') otherQuote = '“'; | ||
| 656 | + if (c == '‘') otherQuote = '’'; | ||
| 657 | + if (c == '’') otherQuote = '‘'; | ||
| 658 | + | ||
| 645 | 659 | char cc = nextChar(); | |
| 646 | - while (!EOF && cc != c) { | ||
| 660 | + // In a proper string, all the quotes tested are c. In a curly-quoted | ||
| 661 | + // string, there are three possible end quotes: c, its reverse, and | ||
| 662 | + // the correct straight quote. | ||
| 663 | + while (!EOF && cc != otherQuote && cc != realQuote && cc != c) { | ||
| 647 | 664 | buf.append(cc); | |
| 648 | 665 | if (cc == '\\') { | |
| 649 | 666 | buf.append(cc = nextChar()); | |
| 650 | 667 | } | |
| 651 | - if (cc == '\n') { | ||
| 652 | - writeIndentedLine(); | ||
| 653 | - startFlag = true; | ||
| 654 | - } | ||
| 668 | + | ||
| 669 | + // Syntax error: unterminated string. Leave \n in nextChar, so it | ||
| 670 | + // feeds back into the loop. | ||
| 671 | + if (peek() == '\n') break; | ||
| 655 | 672 | cc = nextChar(); | |
| 656 | 673 | } | |
| 657 | - buf.append(cc); | ||
| 658 | - if (readForNewLine()) { | ||
| 659 | - // push a newline into the stream | ||
| 660 | - chars[pos--] = '\n'; | ||
| 674 | + if (cc == otherQuote || cc == realQuote || cc == c) { | ||
| 675 | + buf.append(realQuote); | ||
| 676 | + if (readForNewLine()) { | ||
| 677 | + // push a newline into the stream | ||
| 678 | + chars[pos--] = '\n'; | ||
| 679 | + } | ||
| 680 | + } else { | ||
| 681 | + // We've had a syntax error if the string wasn't terminated by EOL/ | ||
| 682 | + // EOF, just abandon this statement. | ||
| 683 | + inStatementFlag = false; | ||
| 661 | 684 | } | |
| 662 | 685 | break; | |
| 663 | 686 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments