| 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 "dart2jslib.dart"; | 9 import "dart2jslib.dart"; |
| 10 import "tree/tree.dart"; | 10 import "tree/tree.dart"; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 token.charOffset + leftQuote, | 42 token.charOffset + leftQuote, |
| 43 content, | 43 content, |
| 44 quoting); | 44 quoting); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static StringQuoting quotingFromString(SourceString sourceString) { | 47 static StringQuoting quotingFromString(SourceString sourceString) { |
| 48 Iterator<int> source = sourceString.iterator(); | 48 Iterator<int> source = sourceString.iterator(); |
| 49 bool raw = false; | 49 bool raw = false; |
| 50 int quoteLength = 1; | 50 int quoteLength = 1; |
| 51 int quoteChar = source.next(); | 51 int quoteChar = source.next(); |
| 52 if (quoteChar === $r) { | 52 if (identical(quoteChar, $r)) { |
| 53 raw = true; | 53 raw = true; |
| 54 quoteChar = source.next(); | 54 quoteChar = source.next(); |
| 55 } | 55 } |
| 56 assert(quoteChar == $SQ || quoteChar == $DQ); | 56 assert(quoteChar == $SQ || quoteChar == $DQ); |
| 57 // String has at least one quote. Check it if has three. | 57 // String has at least one quote. Check it if has three. |
| 58 // If it only have two, the string must be an empty string literal, | 58 // If it only have two, the string must be an empty string literal, |
| 59 // and end after the second quote. | 59 // and end after the second quote. |
| 60 bool multiline = false; | 60 bool multiline = false; |
| 61 if (source.hasNext && source.next() == quoteChar && source.hasNext) { | 61 if (source.hasNext && source.next() == quoteChar && source.hasNext) { |
| 62 int code = source.next(); | 62 int code = source.next(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 // String literal successfully validated. | 180 // String literal successfully validated. |
| 181 if (quoting.raw || !containsEscape) { | 181 if (quoting.raw || !containsEscape) { |
| 182 // A string without escapes could just as well have been raw. | 182 // A string without escapes could just as well have been raw. |
| 183 return new DartString.rawString(string, length); | 183 return new DartString.rawString(string, length); |
| 184 } | 184 } |
| 185 return new DartString.escapedString(string, length); | 185 return new DartString.escapedString(string, length); |
| 186 } | 186 } |
| 187 } | 187 } |
| OLD | NEW |