Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Unified Diff: sdk/lib/_internal/compiler/implementation/string_validator.dart

Issue 336413002: Allow whitespace and \ before the first newline of multiline string. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use more intuitive test. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/string_validator.dart
diff --git a/sdk/lib/_internal/compiler/implementation/string_validator.dart b/sdk/lib/_internal/compiler/implementation/string_validator.dart
index 140134b955f3310a37ffb4d26743b03db2cd8720..31ae102fafcd4fd4d7456f0c0b964a9768a1f089 100644
--- a/sdk/lib/_internal/compiler/implementation/string_validator.dart
+++ b/sdk/lib/_internal/compiler/implementation/string_validator.dart
@@ -46,25 +46,45 @@ class StringValidator {
}
assert(quoteChar == $SQ || quoteChar == $DQ);
// String has at least one quote. Check it if has three.
- // If it only have two, the string must be an empty string literal,
+ // If it only has two, the string must be an empty string literal,
// and end after the second quote.
bool multiline = false;
if (source.moveNext() && source.current == quoteChar && source.moveNext()) {
int code = source.current;
assert(code == quoteChar); // If not, there is a bug in the parser.
quoteLength = 3;
- // Check if a multiline string starts with a newline (CR, LF or CR+LF).
- if (source.moveNext()) {
+ // Due to string-interpolations we are not guaranteed to see the trailing
+ // quoting characters. The invocations to `moveNext()` may therefore
+ // return false and the `current`-getter return `null`. The code does
+ // not need to handle this specially (as it will not find the newline
+ // characters).
+
+ // Check if a multiline string starts with optional whitespace followed by
+ // a newline (CR, LF or CR+LF).
+ // We also accept if the these characters are escaped by a backslash.
+ int newLineLength = 1;
+ bool foundWhitespace;
+ do {
+ foundWhitespace = false;
Lasse Reichstein Nielsen 2014/06/18 09:05:32 This "break variable" is more confusing than a "wh
floitsch 2014/06/18 12:14:22 changed to while(true). Initially switched away fr
+ source.moveNext();
Lasse Reichstein Nielsen 2014/06/18 09:05:32 Why is the return value of moveNext not checked? I
floitsch 2014/06/18 12:14:22 Moved comment from line 56 to here.
code = source.current;
- if (code == $CR) {
- quoteLength += 1;
+ if (code == $BACKSLASH) {
+ newLineLength++;
+ source.moveNext();
+ code = source.current;
+ }
+ if (code == $TAB || code == $SPACE) {
+ newLineLength++;
+ foundWhitespace = true;
+ } else if (code == $CR) {
Lasse Reichstein Nielsen 2014/06/18 09:05:32 The spec says "If the first line of a multiline ..
if (source.moveNext() && source.current == $LF) {
Lasse Reichstein Nielsen 2014/06/18 09:05:32 Does the spec require \\\r\\\n to work as a newlin
- quoteLength += 1;
+ newLineLength++;
}
+ quoteLength += newLineLength;
} else if (code == $LF) {
- quoteLength += 1;
+ quoteLength += newLineLength;
}
- }
+ } while (foundWhitespace);
}
return StringQuoting.getQuoting(quoteChar, raw, quoteLength);
Johnni Winther 2014/06/18 08:43:44 StringQuoting.getQuoting expects [quoteLength] to
floitsch 2014/06/18 12:14:23 It shouldn't anymore. I changed it to be accept an
}

Powered by Google App Engine
This is Rietveld 408576698