Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: pkg/http/lib/src/utils.dart

Issue 14958005: Default to UTF-8 in the HTTP package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/lib/src/byte_stream.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:typed_data'; 10 import 'dart:typed_data';
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 /// [FormatException] if no [Encoding] was found that corresponds to [charset]. 87 /// [FormatException] if no [Encoding] was found that corresponds to [charset].
88 /// [charset] may not be null. 88 /// [charset] may not be null.
89 Encoding requiredEncodingForCharset(String charset) { 89 Encoding requiredEncodingForCharset(String charset) {
90 var encoding = Encoding.fromName(charset); 90 var encoding = Encoding.fromName(charset);
91 if (encoding != null) return encoding; 91 if (encoding != null) return encoding;
92 throw new FormatException('Unsupported encoding "$charset".'); 92 throw new FormatException('Unsupported encoding "$charset".');
93 } 93 }
94 94
95 /// Converts [bytes] into a [String] according to [encoding]. 95 /// Converts [bytes] into a [String] according to [encoding].
96 String decodeString(List<int> bytes, Encoding encoding) { 96 String decodeString(List<int> bytes, Encoding encoding) {
97 // TODO(nweiz): implement this once issue 6284 is fixed. 97 // TODO(nweiz): implement this once issue 6284 is fixed.
Bob Nystrom 2013/05/16 16:11:39 How about throwing NotImplementedError if [encodin
nweiz 2013/05/16 18:32:46 I suspect most of the time when encodings get set
98 return new String.fromCharCodes(bytes); 98 return decodeUtf8(bytes);
99 } 99 }
100 100
101 /// Converts [string] into a byte array according to [encoding]. 101 /// Converts [string] into a byte array according to [encoding].
102 List<int> encodeString(String string, Encoding encoding) { 102 List<int> encodeString(String string, Encoding encoding) {
103 // TODO(nweiz): implement this once issue 6284 is fixed. 103 // TODO(nweiz): implement this once issue 6284 is fixed.
Bob Nystrom 2013/05/16 16:11:39 Ditto.
104 return string.codeUnits; 104 return encodeUtf8(string);
105 } 105 }
106 106
107 /// A regular expression that matches strings that are composed entirely of 107 /// A regular expression that matches strings that are composed entirely of
108 /// ASCII-compatible characters. 108 /// ASCII-compatible characters.
109 final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$"); 109 final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$");
110 110
111 /// Returns whether [string] is composed entirely of ASCII-compatible 111 /// Returns whether [string] is composed entirely of ASCII-compatible
112 /// characters. 112 /// characters.
113 bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string); 113 bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string);
114 114
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 /// The return values of all [Future]s are discarded. Any errors will cause the 232 /// The return values of all [Future]s are discarded. Any errors will cause the
233 /// iteration to stop and will be piped through the return value. 233 /// iteration to stop and will be piped through the return value.
234 Future forEachFuture(Iterable input, Future fn(element)) { 234 Future forEachFuture(Iterable input, Future fn(element)) {
235 var iterator = input.iterator; 235 var iterator = input.iterator;
236 Future nextElement(_) { 236 Future nextElement(_) {
237 if (!iterator.moveNext()) return new Future.value(); 237 if (!iterator.moveNext()) return new Future.value();
238 return fn(iterator.current).then(nextElement); 238 return fn(iterator.current).then(nextElement);
239 } 239 }
240 return nextElement(null); 240 return nextElement(null);
241 } 241 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/byte_stream.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698