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

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: Forgot to save. 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..d967e44799ccca757a2ae93acca71b2888500869 100644
--- a/sdk/lib/_internal/compiler/implementation/string_validator.dart
+++ b/sdk/lib/_internal/compiler/implementation/string_validator.dart
@@ -36,7 +36,7 @@ class StringValidator {
static StringQuoting quotingFromString(String sourceString) {
Iterator<int> source = sourceString.codeUnits.iterator;
bool raw = false;
- int quoteLength = 1;
+ int leftQuoteLength = 1;
source.moveNext();
int quoteChar = source.current;
if (quoteChar == $r) {
@@ -46,27 +46,47 @@ 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()) {
+ leftQuoteLength = 3;
+
+ // 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;
+ while (true) {
+ // 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).
+ source.moveNext();
code = source.current;
+ if (code == $BACKSLASH) {
+ newLineLength++;
+ source.moveNext();
+ code = source.current;
+ }
+ if (code == $TAB || code == $SPACE) {
+ newLineLength++;
+ continue;
+ }
if (code == $CR) {
- quoteLength += 1;
if (source.moveNext() && source.current == $LF) {
- quoteLength += 1;
+ newLineLength++;
}
+ leftQuoteLength += newLineLength;
} else if (code == $LF) {
- quoteLength += 1;
+ leftQuoteLength += newLineLength;
}
+ break;
}
}
- return StringQuoting.getQuoting(quoteChar, raw, quoteLength);
+ return StringQuoting.getQuoting(quoteChar, raw, leftQuoteLength);
}
/**

Powered by Google App Engine
This is Rietveld 408576698