OLD | NEW |
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 /** The Unicode Replacement character `U+FFFD` (�). */ | 7 /** The Unicode Replacement character `U+FFFD` (�). */ |
8 const int UNICODE_REPLACEMENT_CHARACTER_RUNE = 0xFFFD; | 8 const int UNICODE_REPLACEMENT_CHARACTER_RUNE = 0xFFFD; |
9 | 9 |
10 /** The Unicode Byte Order Marker (BOM) character `U+FEFF`. */ | 10 /** The Unicode Byte Order Marker (BOM) character `U+FEFF`. */ |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 Utf8Encoder get encoder => const Utf8Encoder(); | 69 Utf8Encoder get encoder => const Utf8Encoder(); |
70 Utf8Decoder get decoder { | 70 Utf8Decoder get decoder { |
71 return new Utf8Decoder(allowMalformed: _allowMalformed); | 71 return new Utf8Decoder(allowMalformed: _allowMalformed); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 /** | 75 /** |
76 * This class converts strings to their UTF-8 code units (a list of | 76 * This class converts strings to their UTF-8 code units (a list of |
77 * unsigned 8-bit integers). | 77 * unsigned 8-bit integers). |
78 */ | 78 */ |
79 class Utf8Encoder extends Converter<String, List<int>> { | 79 class Utf8Encoder extends |
| 80 ChunkedConverter<String, List<int>, String, List<int>> { |
80 | 81 |
81 const Utf8Encoder(); | 82 const Utf8Encoder(); |
82 | 83 |
83 /** | 84 /** |
84 * Converts [string] to its UTF-8 code units (a list of | 85 * Converts [string] to its UTF-8 code units (a list of |
85 * unsigned 8-bit integers). | 86 * unsigned 8-bit integers). |
86 * | 87 * |
87 * If [start] and [end] are provided, only the substring | 88 * If [start] and [end] are provided, only the substring |
88 * `string.substring(start, end)` is converted. | 89 * `string.substring(start, end)` is converted. |
89 */ | 90 */ |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 298 } |
298 | 299 |
299 // TODO(floitsch): implement asUtf8Sink. Sligthly complicated because it | 300 // TODO(floitsch): implement asUtf8Sink. Sligthly complicated because it |
300 // needs to deal with malformed input. | 301 // needs to deal with malformed input. |
301 } | 302 } |
302 | 303 |
303 /** | 304 /** |
304 * This class converts UTF-8 code units (lists of unsigned 8-bit integers) | 305 * This class converts UTF-8 code units (lists of unsigned 8-bit integers) |
305 * to a string. | 306 * to a string. |
306 */ | 307 */ |
307 class Utf8Decoder extends Converter<List<int>, String> { | 308 class Utf8Decoder extends |
| 309 ChunkedConverter<List<int>, String, List<int>, String> { |
308 final bool _allowMalformed; | 310 final bool _allowMalformed; |
309 | 311 |
310 /** | 312 /** |
311 * Instantiates a new [Utf8Decoder]. | 313 * Instantiates a new [Utf8Decoder]. |
312 * | 314 * |
313 * The optional [allowMalformed] argument defines how [convert] deals | 315 * The optional [allowMalformed] argument defines how [convert] deals |
314 * with invalid or unterminated character sequences. | 316 * with invalid or unterminated character sequences. |
315 * | 317 * |
316 * If it is `true` [convert] replaces invalid (or unterminated) character | 318 * If it is `true` [convert] replaces invalid (or unterminated) character |
317 * sequences with the Unicode Replacement character `U+FFFD` (�). Otherwise | 319 * sequences with the Unicode Replacement character `U+FFFD` (�). Otherwise |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 } | 564 } |
563 break loop; | 565 break loop; |
564 } | 566 } |
565 if (expectedUnits > 0) { | 567 if (expectedUnits > 0) { |
566 _value = value; | 568 _value = value; |
567 _expectedUnits = expectedUnits; | 569 _expectedUnits = expectedUnits; |
568 _extraUnits = extraUnits; | 570 _extraUnits = extraUnits; |
569 } | 571 } |
570 } | 572 } |
571 } | 573 } |
OLD | NEW |