| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 stringParseError("Invalid character in escape sequence", | 161 stringParseError("Invalid character in escape sequence", |
| 162 token, index); | 162 token, index); |
| 163 return null; | 163 return null; |
| 164 } | 164 } |
| 165 value = value * 16 + hexDigitValue(code); | 165 value = value * 16 + hexDigitValue(code); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 code = value; | 168 code = value; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 // TODO(erikcorry): Use the string code point iterator when available. | |
| 172 if (code >= String.SUPPLEMENTARY_CODE_POINT_BASE) ++length;; | |
| 173 // This handles both unescaped characters and the value of unicode | 171 // This handles both unescaped characters and the value of unicode |
| 174 // escapes. | 172 // escapes. |
| 175 if (!isUnicodeScalarValue(code)) { | 173 if (!isUnicodeScalarValue(code)) { |
| 176 stringParseError( | 174 stringParseError( |
| 177 "Invalid Unicode scalar value U+${code.toRadixString(16)}", | 175 "Invalid Unicode scalar value U+${code.toRadixString(16)}", |
| 178 token, index); | 176 token, index); |
| 179 return null; | 177 return null; |
| 180 } | 178 } |
| 181 } | 179 } |
| 182 // String literal successfully validated. | 180 // String literal successfully validated. |
| 183 if (quoting.raw || !containsEscape) { | 181 if (quoting.raw || !containsEscape) { |
| 184 // A string without escapes could just as well have been raw. | 182 // A string without escapes could just as well have been raw. |
| 185 return new DartString.rawString(string, length); | 183 return new DartString.rawString(string, length); |
| 186 } | 184 } |
| 187 return new DartString.escapedString(string, length); | 185 return new DartString.escapedString(string, length); |
| 188 } | 186 } |
| 189 } | 187 } |
| OLD | NEW |