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

Unified Diff: frog/leg/string_validator.dart

Issue 9301037: Made multiline string literals ignore an initial newline. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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: frog/leg/string_validator.dart
diff --git a/frog/leg/string_validator.dart b/frog/leg/string_validator.dart
index c83fe6f291e077b4a53352a7f205ea9dd02e0213..28ab570f80c405f2b31bbbf024bc525eacf0b847 100644
--- a/frog/leg/string_validator.dart
+++ b/frog/leg/string_validator.dart
@@ -47,6 +47,7 @@ class StringValidator {
static StringQuoting quotingFromString(SourceString sourceString) {
Iterator<int> source = sourceString.iterator();
bool raw = false;
+ int quoteLength = 1;
int quoteChar = source.next();
if (quoteChar == $AT) {
raw = true;
@@ -57,11 +58,24 @@ class StringValidator {
// If it only have two, the string must be an empty string literal,
// and end after the second quote.
bool multiline = false;
- if (source.hasNext() && source.next() == quoteChar && source.hasNext()) {
- assert(source.next() == quoteChar);
- multiline = true;
+ if (source.hasNext() && source.next() === quoteChar && source.hasNext()) {
+ int code = source.next();
+ 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.hasNext()) {
+ code = source.next();
+ if (code === $CR) {
+ quoteLength += 1;
+ if (source.hasNext() && source.next() === $LF) {
+ quoteLength += 1;
+ }
+ } else if (code === $LF) {
+ quoteLength += 1;
+ }
+ }
}
- return StringQuoting.get(quoteChar, raw, multiline);
+ return StringQuoting.get(quoteChar, raw, quoteLength);
}
void stringParseError(String message, Token token, int offset) {

Powered by Google App Engine
This is Rietveld 408576698