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.SMP_CODE_POINT_BASE) ++length;; |
171 // This handles both unescaped characters and the value of unicode | 173 // This handles both unescaped characters and the value of unicode |
172 // escapes. | 174 // escapes. |
173 if (!isUnicodeScalarValue(code)) { | 175 if (!isUnicodeScalarValue(code)) { |
174 stringParseError( | 176 stringParseError( |
175 "Invalid Unicode scalar value U+${code.toRadixString(16)}", | 177 "Invalid Unicode scalar value U+${code.toRadixString(16)}", |
176 token, index); | 178 token, index); |
177 return null; | 179 return null; |
178 } | 180 } |
179 } | 181 } |
180 // String literal successfully validated. | 182 // String literal successfully validated. |
181 if (quoting.raw || !containsEscape) { | 183 if (quoting.raw || !containsEscape) { |
182 // A string without escapes could just as well have been raw. | 184 // A string without escapes could just as well have been raw. |
183 return new DartString.rawString(string, length); | 185 return new DartString.rawString(string, length); |
184 } | 186 } |
185 return new DartString.escapedString(string, length); | 187 return new DartString.escapedString(string, length); |
186 } | 188 } |
187 } | 189 } |
OLD | NEW |