| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 * literals (including an initial 'r' for raw strings). | 75 * literals (including an initial 'r' for raw strings). |
| 76 */ | 76 */ |
| 77 String copyWithoutQuotes(String string, int initial, int terminal) { | 77 String copyWithoutQuotes(String string, int initial, int terminal) { |
| 78 assert(0 <= initial); | 78 assert(0 <= initial); |
| 79 assert(0 <= terminal); | 79 assert(0 <= terminal); |
| 80 assert(initial + terminal <= string.length); | 80 assert(initial + terminal <= string.length); |
| 81 return string.substring(initial, string.length - terminal); | 81 return string.substring(initial, string.length - terminal); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void stringParseError(String message, Token token, int offset) { | 84 void stringParseError(String message, Token token, int offset) { |
| 85 listener.cancel("$message @ $offset", token : token); | 85 listener.reportFatalError( |
| 86 token, MessageKind.GENERIC, {'text': "$message @ $offset"}); |
| 86 } | 87 } |
| 87 | 88 |
| 88 /** | 89 /** |
| 89 * Validates the escape sequences and special characters of a string literal. | 90 * Validates the escape sequences and special characters of a string literal. |
| 90 * Returns a DartString if valid, and null if not. | 91 * Returns a DartString if valid, and null if not. |
| 91 */ | 92 */ |
| 92 DartString validateString(Token token, | 93 DartString validateString(Token token, |
| 93 int startOffset, | 94 int startOffset, |
| 94 String string, | 95 String string, |
| 95 StringQuoting quoting) { | 96 StringQuoting quoting) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 return null; | 206 return null; |
| 206 } | 207 } |
| 207 // String literal successfully validated. | 208 // String literal successfully validated. |
| 208 if (quoting.raw || !containsEscape) { | 209 if (quoting.raw || !containsEscape) { |
| 209 // A string without escapes could just as well have been raw. | 210 // A string without escapes could just as well have been raw. |
| 210 return new DartString.rawString(string, length); | 211 return new DartString.rawString(string, length); |
| 211 } | 212 } |
| 212 return new DartString.escapedString(string, length); | 213 return new DartString.escapedString(string, length); |
| 213 } | 214 } |
| 214 } | 215 } |
| OLD | NEW |