| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Check the validity of string literals. | 5 // Check the validity of string literals. |
| 6 | 6 |
| 7 library stringvalidator; | 7 library stringvalidator; |
| 8 | 8 |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // String has at least one quote. Check it if has three. | 45 // String has at least one quote. Check it if has three. |
| 46 // If it only has two, the string must be an empty string literal, | 46 // If it only has two, the string must be an empty string literal, |
| 47 // and end after the second quote. | 47 // and end after the second quote. |
| 48 if (source.moveNext() && source.current == quoteChar && source.moveNext()) { | 48 if (source.moveNext() && source.current == quoteChar && source.moveNext()) { |
| 49 int code = source.current; | 49 int code = source.current; |
| 50 assert(code == quoteChar); // If not, there is a bug in the parser. | 50 assert(code == quoteChar); // If not, there is a bug in the parser. |
| 51 leftQuoteLength = 3; | 51 leftQuoteLength = 3; |
| 52 | 52 |
| 53 // Check if a multiline string starts with optional whitespace followed by | 53 // Check if a multiline string starts with optional whitespace followed by |
| 54 // a newline (CR, LF or CR+LF). | 54 // a newline (CR, LF or CR+LF). |
| 55 // We also accept if the these characters are escaped by a backslash. | 55 // We also accept if these characters are escaped by a backslash. |
| 56 int newLineLength = 1; | 56 int newLineLength = 1; |
| 57 while (true) { | 57 while (true) { |
| 58 // Due to string-interpolations we are not guaranteed to see the | 58 // Due to string-interpolations we are not guaranteed to see the |
| 59 // trailing quoting characters. The invocations to `moveNext()` may | 59 // trailing quoting characters. The invocations to `moveNext()` may |
| 60 // therefore return false and the `current`-getter return `null`. The | 60 // therefore return false and the `current`-getter return `null`. The |
| 61 // code does not need to handle this specially (as it will not find the | 61 // code does not need to handle this specially (as it will not find the |
| 62 // newline characters). | 62 // newline characters). |
| 63 source.moveNext(); | 63 source.moveNext(); |
| 64 code = source.current; | 64 code = source.current; |
| 65 if (code == $BACKSLASH) { | 65 if (code == $BACKSLASH) { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 return null; | 219 return null; |
| 220 } | 220 } |
| 221 // String literal successfully validated. | 221 // String literal successfully validated. |
| 222 if (quoting.raw || !containsEscape) { | 222 if (quoting.raw || !containsEscape) { |
| 223 // A string without escapes could just as well have been raw. | 223 // A string without escapes could just as well have been raw. |
| 224 return new DartString.rawString(string, length); | 224 return new DartString.rawString(string, length); |
| 225 } | 225 } |
| 226 return new DartString.escapedString(string, length); | 226 return new DartString.escapedString(string, length); |
| 227 } | 227 } |
| 228 } | 228 } |
| OLD | NEW |