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.utf; | 5 part of dart.utf; |
6 | 6 |
7 class _HelperStreamController<T> extends StreamController<T> { | 7 class _HelperStreamController<T> extends StreamController<T> { |
8 final Function onPauseChanged; | 8 final Function onPauseChanged; |
9 | 9 |
10 _HelperStreamController(this.onPauseChanged); | 10 _HelperStreamController(this.onPauseChanged); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 List<int> _processString(String string); | 185 List<int> _processString(String string); |
186 } | 186 } |
187 | 187 |
188 /** | 188 /** |
189 * StringTransformer that UTF-8 encodes a stream of strings. | 189 * StringTransformer that UTF-8 encodes a stream of strings. |
190 */ | 190 */ |
191 class Utf8EncoderTransformer extends _StringEncoder { | 191 class Utf8EncoderTransformer extends _StringEncoder { |
192 List<int> _processString(String string) { | 192 List<int> _processString(String string) { |
193 var bytes = []; | 193 var bytes = []; |
194 int pos = 0; | 194 int pos = 0; |
195 List<int> codepoints = _utf16CodeUnitsToCodepoints(string.charCodes); | 195 List<int> codepoints = _utf16CodeUnitsToCodepoints(string.codeUnits); |
196 int length = codepoints.length; | 196 int length = codepoints.length; |
197 for (int i = 0; i < length; i++) { | 197 for (int i = 0; i < length; i++) { |
198 int additionalBytes; | 198 int additionalBytes; |
199 int charCode = codepoints[i]; | 199 int charCode = codepoints[i]; |
200 if (charCode <= 0x007F) { | 200 if (charCode <= 0x007F) { |
201 additionalBytes = 0; | 201 additionalBytes = 0; |
202 bytes.add(charCode); | 202 bytes.add(charCode); |
203 } else if (charCode <= 0x07FF) { | 203 } else if (charCode <= 0x07FF) { |
204 // 110xxxxx (xxxxx is top 5 bits). | 204 // 110xxxxx (xxxxx is top 5 bits). |
205 bytes.add(((charCode >> 6) & 0x1F) | 0xC0); | 205 bytes.add(((charCode >> 6) & 0x1F) | 0xC0); |
206 additionalBytes = 1; | 206 additionalBytes = 1; |
207 } else if (charCode <= 0xFFFF) { | 207 } else if (charCode <= 0xFFFF) { |
208 // 1110xxxx (xxxx is top 4 bits) | 208 // 1110xxxx (xxxx is top 4 bits) |
209 bytes.add(((charCode >> 12) & 0x0F)| 0xE0); | 209 bytes.add(((charCode >> 12) & 0x0F)| 0xE0); |
210 additionalBytes = 2; | 210 additionalBytes = 2; |
211 } else { | 211 } else { |
212 // 11110xxx (xxx is top 3 bits) | 212 // 11110xxx (xxx is top 3 bits) |
213 bytes.add(((charCode >> 18) & 0x07) | 0xF0); | 213 bytes.add(((charCode >> 18) & 0x07) | 0xF0); |
214 additionalBytes = 3; | 214 additionalBytes = 3; |
215 } | 215 } |
216 for (int i = additionalBytes; i > 0; i--) { | 216 for (int i = additionalBytes; i > 0; i--) { |
217 // 10xxxxxx (xxxxxx is next 6 bits from the top). | 217 // 10xxxxxx (xxxxxx is next 6 bits from the top). |
218 bytes.add(((charCode >> (6 * (i - 1))) & 0x3F) | 0x80); | 218 bytes.add(((charCode >> (6 * (i - 1))) & 0x3F) | 0x80); |
219 } | 219 } |
220 pos += additionalBytes + 1; | 220 pos += additionalBytes + 1; |
221 } | 221 } |
222 return bytes; | 222 return bytes; |
223 } | 223 } |
224 } | 224 } |
OLD | NEW |