Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: lib/compiler/implementation/string_validator.dart

Issue 11318018: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 StringQuoting quoting) { 92 StringQuoting quoting) {
93 // We only need to check for invalid x and u escapes, for line 93 // We only need to check for invalid x and u escapes, for line
94 // terminators in non-multiline strings, and for invalid Unicode 94 // terminators in non-multiline strings, and for invalid Unicode
95 // scalar values (either directly or as u-escape values). 95 // scalar values (either directly or as u-escape values).
96 int length = 0; 96 int length = 0;
97 int index = startOffset; 97 int index = startOffset;
98 bool containsEscape = false; 98 bool containsEscape = false;
99 for(Iterator<int> iter = string.iterator(); iter.hasNext; length++) { 99 for(Iterator<int> iter = string.iterator(); iter.hasNext; length++) {
100 index++; 100 index++;
101 int code = iter.next(); 101 int code = iter.next();
102 bool verify_code = false;
ngeoffray 2012/10/27 09:02:00 verify_code -> verifyCode
102 if (code == $BACKSLASH) { 103 if (code == $BACKSLASH) {
104 verify_code = true;
103 if (quoting.raw) continue; 105 if (quoting.raw) continue;
104 containsEscape = true; 106 containsEscape = true;
105 if (!iter.hasNext) { 107 if (!iter.hasNext) {
106 stringParseError("Incomplete escape sequence",token, index); 108 stringParseError("Incomplete escape sequence",token, index);
107 return null; 109 return null;
108 } 110 }
109 index++; 111 index++;
110 code = iter.next(); 112 code = iter.next();
111 if (code == $x) { 113 if (code == $x) {
112 for (int i = 0; i < 2; i++) { 114 for (int i = 0; i < 2; i++) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 stringParseError("Invalid character in escape sequence", 163 stringParseError("Invalid character in escape sequence",
162 token, index); 164 token, index);
163 return null; 165 return null;
164 } 166 }
165 value = value * 16 + hexDigitValue(code); 167 value = value * 16 + hexDigitValue(code);
166 } 168 }
167 } 169 }
168 code = value; 170 code = value;
169 } 171 }
170 } 172 }
171 // This handles both unescaped characters and the value of unicode 173 // This handles both unescaped characters and the value of unicode
ahe 2012/10/28 12:07:02 I don't think this comment is correct any more.
172 // escapes. 174 // escapes.
173 if (!isUnicodeScalarValue(code)) { 175 if (verify_code && !isUnicodeScalarValue(code)) {
ahe 2012/10/28 12:07:02 This doesn't look right to me. If we are switching
cshapiro 2012/10/29 06:37:17 The specification for string literals was delibera
ahe 2012/10/29 08:11:07 If the underlying string representation is UTF-16,
siva 2012/10/31 01:21:26 I have decided to drop these changes made to dart2
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698