OLD | NEW |
---|---|
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 part of dart.utf; | 5 part of dart.utf; |
6 | 6 |
7 /** | 7 /** |
8 * Decodes the UTF-32 bytes as an iterable. Thus, the consumer can only convert | 8 * Decodes the UTF-32 bytes as an iterable. Thus, the consumer can only convert |
9 * as much of the input as needed. Determines the byte order from the BOM, | 9 * as much of the input as needed. Determines the byte order from the BOM, |
10 * or uses big-endian as a default. This method always strips a leading BOM. | 10 * or uses big-endian as a default. This method always strips a leading BOM. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 | 50 |
51 /** | 51 /** |
52 * Produce a String from a sequence of UTF-32 encoded bytes. The parameters | 52 * Produce a String from a sequence of UTF-32 encoded bytes. The parameters |
53 * allow an offset into a list of bytes (as int), limiting the length of the | 53 * allow an offset into a list of bytes (as int), limiting the length of the |
54 * values be decoded and the ability of override the default Unicode | 54 * values be decoded and the ability of override the default Unicode |
55 * replacement character. Set the replacementCharacter to null to throw an | 55 * replacement character. Set the replacementCharacter to null to throw an |
56 * ArgumentError rather than replace the bad value. | 56 * ArgumentError rather than replace the bad value. |
57 */ | 57 */ |
58 String decodeUtf32(List<int> bytes, [int offset = 0, int length, | 58 String decodeUtf32(List<int> bytes, [int offset = 0, int length, |
59 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { | 59 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) { |
60 return codepointsToString((new Utf32BytesDecoder(bytes, offset, length, | 60 return new String.fromCharCodes((new Utf32BytesDecoder(bytes, offset, length, |
61 replacementCodepoint)).decodeRest()); | 61 replacementCodepoint)).decodeRest()); |
62 } | 62 } |
63 /** | 63 /** |
64 * Produce a String from a sequence of UTF-32BE encoded bytes. The parameters | 64 * Produce a String from a sequence of UTF-32BE encoded bytes. The parameters |
65 * allow an offset into a list of bytes (as int), limiting the length of the | 65 * allow an offset into a list of bytes (as int), limiting the length of the |
66 * values be decoded and the ability of override the default Unicode | 66 * values be decoded and the ability of override the default Unicode |
67 * replacement character. Set the replacementCharacter to null to throw an | 67 * replacement character. Set the replacementCharacter to null to throw an |
68 * ArgumentError rather than replace the bad value. | 68 * ArgumentError rather than replace the bad value. |
69 */ | 69 */ |
70 String decodeUtf32be( | 70 String decodeUtf32be( |
71 List<int> bytes, [int offset = 0, int length, bool stripBom = true, | 71 List<int> bytes, [int offset = 0, int length, bool stripBom = true, |
72 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) => | 72 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) => |
73 codepointsToString((new Utf32beBytesDecoder(bytes, offset, length, stripBom, | 73 new String.fromCharCodes((new Utf32beBytesDecoder(bytes, offset, length, strip Bom, |
nweiz
2013/04/08 20:41:19
Line length.
| |
74 replacementCodepoint)).decodeRest()); | 74 replacementCodepoint)).decodeRest()); |
75 | 75 |
76 /** | 76 /** |
77 * Produce a String from a sequence of UTF-32LE encoded bytes. The parameters | 77 * Produce a String from a sequence of UTF-32LE encoded bytes. The parameters |
78 * allow an offset into a list of bytes (as int), limiting the length of the | 78 * allow an offset into a list of bytes (as int), limiting the length of the |
79 * values be decoded and the ability of override the default Unicode | 79 * values be decoded and the ability of override the default Unicode |
80 * replacement character. Set the replacementCharacter to null to throw an | 80 * replacement character. Set the replacementCharacter to null to throw an |
81 * ArgumentError rather than replace the bad value. | 81 * ArgumentError rather than replace the bad value. |
82 */ | 82 */ |
83 String decodeUtf32le( | 83 String decodeUtf32le( |
84 List<int> bytes, [int offset = 0, int length, bool stripBom = true, | 84 List<int> bytes, [int offset = 0, int length, bool stripBom = true, |
85 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) => | 85 int replacementCodepoint = UNICODE_REPLACEMENT_CHARACTER_CODEPOINT]) => |
86 codepointsToString((new Utf32leBytesDecoder(bytes, offset, length, stripBom, | 86 new String.fromCharCodes((new Utf32leBytesDecoder(bytes, offset, length, str ipBom, |
nweiz
2013/04/08 20:41:19
Line length.
| |
87 replacementCodepoint)).decodeRest()); | 87 replacementCodepoint)).decodeRest()); |
88 | 88 |
89 /** | 89 /** |
90 * Produce a list of UTF-32 encoded bytes. This method prefixes the resulting | 90 * Produce a list of UTF-32 encoded bytes. This method prefixes the resulting |
91 * bytes with a big-endian byte-order-marker. | 91 * bytes with a big-endian byte-order-marker. |
92 */ | 92 */ |
93 List<int> encodeUtf32(String str) => | 93 List<int> encodeUtf32(String str) => |
94 encodeUtf32be(str, true); | 94 encodeUtf32be(str, true); |
95 | 95 |
96 /** | 96 /** |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 value += (utf32EncodedBytesIterator.current << 24); | 329 value += (utf32EncodedBytesIterator.current << 24); |
330 return value; | 330 return value; |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 bool _validCodepoint(int codepoint) { | 334 bool _validCodepoint(int codepoint) { |
335 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || | 335 return (codepoint >= 0 && codepoint < UNICODE_UTF16_RESERVED_LO) || |
336 (codepoint > UNICODE_UTF16_RESERVED_HI && | 336 (codepoint > UNICODE_UTF16_RESERVED_HI && |
337 codepoint < UNICODE_VALID_RANGE_MAX); | 337 codepoint < UNICODE_VALID_RANGE_MAX); |
338 } | 338 } |
OLD | NEW |