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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 token, index); | 165 token, index); |
166 return null; | 166 return null; |
167 } | 167 } |
168 value = value * 16 + hexDigitValue(code); | 168 value = value * 16 + hexDigitValue(code); |
169 } | 169 } |
170 } | 170 } |
171 code = value; | 171 code = value; |
172 } | 172 } |
173 } | 173 } |
174 if (code >= 0x10000) length++; | 174 if (code >= 0x10000) length++; |
175 assert(code <= 0x10ffff); | |
176 // This handles both unescaped characters and the value of unicode | 175 // This handles both unescaped characters and the value of unicode |
177 // escapes. | 176 // escapes. |
178 if (previousWasLeadSurrogate) { | 177 if (previousWasLeadSurrogate) { |
179 if (!isUtf16TrailSurrogate(code)) { | 178 if (!isUtf16TrailSurrogate(code)) { |
180 invalidUtf16 = true; | 179 invalidUtf16 = true; |
181 break; | 180 break; |
182 } | 181 } |
183 previousWasLeadSurrogate = false; | 182 previousWasLeadSurrogate = false; |
184 } else if (isUtf16LeadSurrogate(code)) { | 183 } else if (isUtf16LeadSurrogate(code)) { |
185 previousWasLeadSurrogate = true; | 184 previousWasLeadSurrogate = true; |
186 } else if (!isUnicodeScalarValue(code)) { | 185 } else if (!isUnicodeScalarValue(code)) { |
187 invalidUtf16 = true; | 186 invalidUtf16 = true; |
188 break; | 187 break; |
189 } | 188 } |
190 } | 189 } |
191 if (previousWasLeadSurrogate || invalidUtf16) { | 190 if (previousWasLeadSurrogate || invalidUtf16) { |
192 stringParseError("Invalid Utf16 surrogate", token, index); | 191 stringParseError("Invalid Utf16 surrogate", token, index); |
193 return null; | 192 return null; |
194 } | 193 } |
195 // String literal successfully validated. | 194 // String literal successfully validated. |
196 if (quoting.raw || !containsEscape) { | 195 if (quoting.raw || !containsEscape) { |
197 // A string without escapes could just as well have been raw. | 196 // A string without escapes could just as well have been raw. |
198 return new DartString.rawString(string, length); | 197 return new DartString.rawString(string, length); |
199 } | 198 } |
200 return new DartString.escapedString(string, length); | 199 return new DartString.escapedString(string, length); |
201 } | 200 } |
202 } | 201 } |
OLD | NEW |