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

Unified Diff: runtime/vm/scanner.cc

Issue 24493007: Discard first line of multiline string if only whitespace (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 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
« no previous file with comments | « runtime/vm/scanner.h ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/scanner.cc
===================================================================
--- runtime/vm/scanner.cc (revision 27888)
+++ runtime/vm/scanner.cc (working copy)
@@ -422,19 +422,14 @@
// Entering string scanning mode.
BeginStringLiteral(c0_);
- string_is_multiline_ = (LookaheadChar(1) == c0_) &&
- (LookaheadChar(2) == c0_);
+ ReadChar();
- ReadChar(); // Skip opening delimiter.
- if (string_is_multiline_) {
+ if ((c0_ == string_delimiter_) && (LookaheadChar(1) == string_delimiter_)) {
+ string_is_multiline_ = true;
ReadChar(); // Skip two additional string delimiters.
ReadChar();
- if (c0_ == '\n') {
- // Skip first character of multiline string if it is a newline.
- ReadChar();
- }
}
- ScanLiteralStringChars(is_raw);
+ ScanLiteralStringChars(is_raw, string_is_multiline_);
}
@@ -497,7 +492,7 @@
}
-void Scanner::ScanLiteralStringChars(bool is_raw) {
+void Scanner::ScanLiteralStringChars(bool is_raw, bool remove_whitespace) {
GrowableArray<int32_t> string_chars(64);
ASSERT(IsScanningString());
@@ -595,6 +590,25 @@
}
string_chars.Add(ch1);
}
+ // The first line of a multi-line string is discarded if it only
+ // contains whitespace.
+ if (remove_whitespace && (string_chars.Last() == '\n')) {
+ bool whitespace_only = true;
+ // Last character is the newline, don't inspect it.
+ const intptr_t len = string_chars.length() - 1;
+ for (int i = 0; i < len; i++) {
+ int32_t ch = string_chars[i];
+ if ((ch != ' ') && (ch != '\t')) {
+ // Non-whitespace character, keep the first line.
+ whitespace_only = false;
+ break;
+ }
+ }
+ if (whitespace_only) {
+ string_chars.Clear(); // Discard characters on first line.
+ }
+ remove_whitespace = false;
+ }
ReadChar();
}
}
@@ -627,7 +641,7 @@
break;
}
} else {
- ScanLiteralStringChars(false);
+ ScanLiteralStringChars(false, false);
}
break;
}
« no previous file with comments | « runtime/vm/scanner.h ('k') | tests/co19/co19-runtime.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698