FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Autoformatter: fix curly quotes. · moisespollo/processing@8bb93c6 · GitHub

Repository navigation

Commit 8bb93c6

Browse files
committed
Autoformatter: fix curly quotes.
Also it now doesn't destroy the rest of the file if a string is left unterminated. Will never fix "content” since curly quotes are valid string content.
1 parent 3babb54 commit 8bb93c6

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

‎java/src/processing/mode/java/AutoFormat.java‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,25 +639,48 @@ public String format(final String source) {
639639
break;
640640

641641
case '"':
642+
case '“':
643+
case '”':
642644
case '\'':
645+
case '‘':
646+
case '’':
643647
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+
645659
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) {
647664
buf.append(cc);
648665
if (cc == '\\') {
649666
buf.append(cc = nextChar());
650667
}
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;
655672
cc = nextChar();
656673
}
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;
661684
}
662685
break;
663686

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL