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 library utils; | 5 library utils; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:crypto'; | 8 import 'dart:crypto'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'dart:scalarlist'; | 10 import 'dart:scalarlist'; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 /// Converts [bytes] into a [String] according to [encoding]. | 105 /// Converts [bytes] into a [String] according to [encoding]. |
106 String decodeString(List<int> bytes, Encoding encoding) { | 106 String decodeString(List<int> bytes, Encoding encoding) { |
107 // TODO(nweiz): implement this once issue 6284 is fixed. | 107 // TODO(nweiz): implement this once issue 6284 is fixed. |
108 return new String.fromCharCodes(bytes); | 108 return new String.fromCharCodes(bytes); |
109 } | 109 } |
110 | 110 |
111 /// Converts [string] into a byte array according to [encoding]. | 111 /// Converts [string] into a byte array according to [encoding]. |
112 List<int> encodeString(String string, Encoding encoding) { | 112 List<int> encodeString(String string, Encoding encoding) { |
113 // TODO(nweiz): implement this once issue 6284 is fixed. | 113 // TODO(nweiz): implement this once issue 6284 is fixed. |
114 return string.charCodes; | 114 return string.codeUnits; |
115 } | 115 } |
116 | 116 |
117 /// A regular expression that matches strings that are composed entirely of | 117 /// A regular expression that matches strings that are composed entirely of |
118 /// ASCII-compatible characters. | 118 /// ASCII-compatible characters. |
119 final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$"); | 119 final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$"); |
120 | 120 |
121 /// Returns whether [string] is composed entirely of ASCII-compatible | 121 /// Returns whether [string] is composed entirely of ASCII-compatible |
122 /// characters. | 122 /// characters. |
123 bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string); | 123 bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string); |
124 | 124 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 /// [StreamController]. This exists to work around issue 8310. | 315 /// [StreamController]. This exists to work around issue 8310. |
316 Stream wrapStream(Stream stream) { | 316 Stream wrapStream(Stream stream) { |
317 var controller = stream.isBroadcast | 317 var controller = stream.isBroadcast |
318 ? new StreamController.broadcast() | 318 ? new StreamController.broadcast() |
319 : new StreamController(); | 319 : new StreamController(); |
320 stream.listen(controller.add, | 320 stream.listen(controller.add, |
321 onError: (e) => controller.signalError(e), | 321 onError: (e) => controller.signalError(e), |
322 onDone: controller.close); | 322 onDone: controller.close); |
323 return controller.stream; | 323 return controller.stream; |
324 } | 324 } |
OLD | NEW |