Chromium Code Reviews| 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
|
| } |