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 Converter<String, List<int>> { |
80 implements ChunkedConverter<String, List<int>, String, List<int>> { | |
81 const Utf8Encoder(); | 80 const Utf8Encoder(); |
82 | 81 |
83 /** | 82 /** |
84 * Converts [string] to its UTF-8 code units (a list of | 83 * Converts [string] to its UTF-8 code units (a list of |
85 * unsigned 8-bit integers). | 84 * unsigned 8-bit integers). |
86 * | 85 * |
87 * If [start] and [end] are provided, only the substring | 86 * If [start] and [end] are provided, only the substring |
88 * `string.substring(start, end)` is converted. | 87 * `string.substring(start, end)` is converted. |
89 */ | 88 */ |
90 List<int> convert(String string, [int start = 0, int end]) { | 89 List<int> convert(String string, [int start = 0, int end]) { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 295 } |
297 | 296 |
298 // TODO(floitsch): implement asUtf8Sink. Sligthly complicated because it | 297 // TODO(floitsch): implement asUtf8Sink. Sligthly complicated because it |
299 // needs to deal with malformed input. | 298 // needs to deal with malformed input. |
300 } | 299 } |
301 | 300 |
302 /** | 301 /** |
303 * This class converts UTF-8 code units (lists of unsigned 8-bit integers) | 302 * This class converts UTF-8 code units (lists of unsigned 8-bit integers) |
304 * to a string. | 303 * to a string. |
305 */ | 304 */ |
306 class Utf8Decoder extends Converter<List<int>, String> | 305 class Utf8Decoder extends Converter<List<int>, String> { |
307 implements ChunkedConverter<List<int>, String, List<int>, String> { | |
308 final bool _allowMalformed; | 306 final bool _allowMalformed; |
309 | 307 |
310 /** | 308 /** |
311 * Instantiates a new [Utf8Decoder]. | 309 * Instantiates a new [Utf8Decoder]. |
312 * | 310 * |
313 * The optional [allowMalformed] argument defines how [convert] deals | 311 * The optional [allowMalformed] argument defines how [convert] deals |
314 * with invalid or unterminated character sequences. | 312 * with invalid or unterminated character sequences. |
315 * | 313 * |
316 * If it is `true` [convert] replaces invalid (or unterminated) character | 314 * If it is `true` [convert] replaces invalid (or unterminated) character |
317 * sequences with the Unicode Replacement character `U+FFFD` (�). Otherwise | 315 * sequences with the Unicode Replacement character `U+FFFD` (�). Otherwise |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 } | 578 } |
581 break loop; | 579 break loop; |
582 } | 580 } |
583 if (expectedUnits > 0) { | 581 if (expectedUnits > 0) { |
584 _value = value; | 582 _value = value; |
585 _expectedUnits = expectedUnits; | 583 _expectedUnits = expectedUnits; |
586 _extraUnits = extraUnits; | 584 _extraUnits = extraUnits; |
587 } | 585 } |
588 } | 586 } |
589 } | 587 } |
OLD | NEW |