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

Side by Side Diff: sdk/lib/convert/utf.dart

Issue 22854028: Fix off-by-one error in UTF-8 encoding. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 months 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.convert; 5 part of dart.convert;
6 6
7 /** 7 /**
8 * An instance of the default implementation of the [Utf8Codec]. 8 * An instance of the default implementation of the [Utf8Codec].
9 * 9 *
10 * This instance provides a convenient access to the most common UTF-8 10 * This instance provides a convenient access to the most common UTF-8
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 int _fillBuffer(String str, int start, int end) { 170 int _fillBuffer(String str, int start, int end) {
171 if (start != end && _isLeadSurrogate(str.codeUnitAt(end - 1))) { 171 if (start != end && _isLeadSurrogate(str.codeUnitAt(end - 1))) {
172 // Don't handle a trailing lead-surrogate in this loop. The caller has 172 // Don't handle a trailing lead-surrogate in this loop. The caller has
173 // to deal with those. 173 // to deal with those.
174 end--; 174 end--;
175 } 175 }
176 int stringIndex; 176 int stringIndex;
177 for (stringIndex = start; stringIndex < end; stringIndex++) { 177 for (stringIndex = start; stringIndex < end; stringIndex++) {
178 int codeUnit = str.codeUnitAt(stringIndex); 178 int codeUnit = str.codeUnitAt(stringIndex);
179 // ASCII has the same representation in UTF-8 and UTF-16. 179 // ASCII has the same representation in UTF-8 and UTF-16.
180 if (codeUnit < _ONE_BYTE_LIMIT) { 180 if (codeUnit <= _ONE_BYTE_LIMIT) {
181 if (_bufferIndex >= _buffer.length) break; 181 if (_bufferIndex >= _buffer.length) break;
182 _buffer[_bufferIndex++] = codeUnit; 182 _buffer[_bufferIndex++] = codeUnit;
183 } else if (_isLeadSurrogate(codeUnit)) { 183 } else if (_isLeadSurrogate(codeUnit)) {
184 if (_bufferIndex + 3 >= _buffer.length) break; 184 if (_bufferIndex + 3 >= _buffer.length) break;
185 // Note that it is safe to read the next code unit. We decremented 185 // Note that it is safe to read the next code unit. We decremented
186 // [end] above when the last valid code unit was a leading surrogate. 186 // [end] above when the last valid code unit was a leading surrogate.
187 int nextCodeUnit = str.codeUnitAt(stringIndex + 1); 187 int nextCodeUnit = str.codeUnitAt(stringIndex + 1);
188 bool wasCombined = _writeSurrogate(codeUnit, nextCodeUnit); 188 bool wasCombined = _writeSurrogate(codeUnit, nextCodeUnit);
189 if (wasCombined) stringIndex++; 189 if (wasCombined) stringIndex++;
190 } else { 190 } else {
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 487 }
488 break loop; 488 break loop;
489 } 489 }
490 if (expectedUnits > 0) { 490 if (expectedUnits > 0) {
491 _value = value; 491 _value = value;
492 _expectedUnits = expectedUnits; 492 _expectedUnits = expectedUnits;
493 _extraUnits = extraUnits; 493 _extraUnits = extraUnits;
494 } 494 }
495 } 495 }
496 } 496 }
OLDNEW
« no previous file with comments | « no previous file | tests/lib/convert/unicode_tests.dart » ('j') | tests/lib/convert/unicode_tests.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698