Chromium Code Reviews| Index: sdk/lib/convert/utf.dart |
| diff --git a/sdk/lib/convert/utf.dart b/sdk/lib/convert/utf.dart |
| index 819013913540a3e403d1cfee98bb9c78ec03419c..34b94dae5fcdbd17c41087af62da079152a040a7 100644 |
| --- a/sdk/lib/convert/utf.dart |
| +++ b/sdk/lib/convert/utf.dart |
| @@ -420,10 +420,24 @@ class _Utf8Decoder { |
| int value = _value; |
| int expectedUnits = _expectedUnits; |
| int extraUnits = _extraUnits; |
| + int singleBytesCount = 0; |
| _value = 0; |
| _expectedUnits = 0; |
| _extraUnits = 0; |
| + void addSingleBytes(int from, int to) { |
| + assert(singleBytesCount > 0); |
| + assert(from >= startIndex && from <= endIndex); |
| + assert(to >= startIndex && to <= endIndex); |
| + if (from == 0 && to == codeUnits.length) { |
| + _stringSink.write(new String.fromCharCodes(codeUnits)); |
| + } else { |
| + _stringSink.write( |
| + new String.fromCharCodes(codeUnits.sublist(from, to))); |
| + } |
| + singleBytesCount = 0; |
| + } |
| + |
| int i = startIndex; |
| loop: while (true) { |
| multibyte: if (expectedUnits > 0) { |
| @@ -479,6 +493,9 @@ class _Utf8Decoder { |
| // https://codereview.chromium.org/22929022/diff/1/sdk/lib/convert/utf.dart?column_width=80 |
| if (unit < 0) { |
| // TODO(floitsch): should this be unit <= 0 ? |
| + if (singleBytesCount > 0) { |
| + addSingleBytes(i - singleBytesCount - 1, i - 1); |
| + } |
| if (!_allowMalformed) { |
| throw new FormatException( |
| "Negative UTF-8 code unit: -0x${(-unit).toRadixString(16)}"); |
| @@ -486,8 +503,11 @@ class _Utf8Decoder { |
| _stringSink.writeCharCode(UNICODE_REPLACEMENT_CHARACTER_RUNE); |
| } else if (unit <= _ONE_BYTE_LIMIT) { |
| _isFirstCharacter = false; |
| - _stringSink.writeCharCode(unit); |
| + singleBytesCount++; |
| } else { |
| + if (singleBytesCount > 0) { |
| + addSingleBytes(i - singleBytesCount - 1, i - 1); |
|
Lasse Reichstein Nielsen
2014/03/24 09:21:01
i - 1 - singleBytesCount
Allows reuse of the (i -
Anders Johnsen
2014/03/24 12:01:01
Done.
|
| + } |
| if ((unit & 0xE0) == 0xC0) { |
| value = unit & 0x1F; |
| expectedUnits = extraUnits = 1; |
| @@ -516,6 +536,9 @@ class _Utf8Decoder { |
| } |
| break loop; |
| } |
| + if (singleBytesCount > 0) { |
| + addSingleBytes(i - singleBytesCount, endIndex); |
| + } |
| if (expectedUnits > 0) { |
| _value = value; |
| _expectedUnits = expectedUnits; |