Skip to content

Commit df6ae38

Browse files
committed
1 parent 3434d6b commit df6ae38

File tree

76 files changed

+556
-902
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+556
-902
lines changed

pkg/analyzer_experimental/bin/analyzer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class BatchRunner {
8080
ErrorSeverity batchResult = ErrorSeverity.NONE;
8181
// read line from stdin
8282
Stream cmdLine = stdin
83-
.transform(new StringDecoder())
83+
.transform(UTF8.decoder)
8484
.transform(new LineSplitter());
8585
var subscription = cmdLine.listen((String line) {
8686
// may be finish

pkg/analyzer_experimental/bin/formatter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ _formatFile(path) {
3737
var buffer = new StringBuffer();
3838
var file = new File(path);
3939
file.openRead()
40-
.transform(new StringDecoder())
40+
.transform(UTF8.decoder)
4141
.listen((data) => buffer.write(data),
4242
onError: (error) => print('Error, could not open "$path"'),
4343
onDone: () => print(_formatCU(buffer.toString())));

pkg/barback/lib/src/asset.dart

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library barback.asset;
66

77
import 'dart:async';
8+
import 'dart:convert' show Encoding, UTF8;
89
import 'dart:io';
910
import 'dart:utf';
1011

@@ -37,7 +38,7 @@ abstract class Asset {
3738
///
3839
/// If the asset was created from a [String] the original string is always
3940
/// returned and [encoding] is ignored. Otherwise, the binary data of the
40-
/// asset is decoded using [encoding], which defaults to [Encoding.UTF_8].
41+
/// asset is decoded using [encoding], which defaults to [UTF8].
4142
Future<String> readAsString({Encoding encoding});
4243

4344
/// Streams the binary contents of the asset.
@@ -54,16 +55,9 @@ class _BinaryAsset extends Asset {
5455
: super(id);
5556

5657
Future<String> readAsString({Encoding encoding}) {
57-
if (encoding == null) encoding = Encoding.UTF_8;
58+
if (encoding == null) encoding = UTF8;
5859

59-
// TODO(rnystrom): When #6284 is fixed, just use that. Until then, only
60-
// UTF-8 is supported. :(
61-
if (encoding != Encoding.UTF_8) {
62-
throw new UnsupportedError(
63-
"${encoding.name} is not a supported encoding.");
64-
}
65-
66-
return new Future.value(decodeUtf8(_contents));
60+
return new Future.value(encoding.decode(_contents));
6761
}
6862

6963
Stream<List<int>> read() => new Future<List<int>>.value(_contents).asStream();
@@ -104,7 +98,7 @@ class _FileAsset extends Asset {
10498
: super(id);
10599

106100
Future<String> readAsString({Encoding encoding}) {
107-
if (encoding == null) encoding = Encoding.UTF_8;
101+
if (encoding == null) encoding = UTF8;
108102
return _file.readAsString(encoding: encoding);
109103
}
110104

pkg/barback/test/asset_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library barback.test.asset_test;
66

77
import 'dart:async';
8+
import 'dart:convert' show Encoding, UTF8, LATIN1;
89
import 'dart:io';
910
import 'dart:utf';
1011

@@ -108,7 +109,7 @@ main() {
108109

109110
test("supports UTF-8", () {
110111
var asset = new Asset.fromBytes(id, encodeUtf8("çøñ†éℵ™"));
111-
expect(asset.readAsString(encoding: Encoding.UTF_8),
112+
expect(asset.readAsString(encoding: UTF8),
112113
completion(equals("çøñ†éℵ™")));
113114
});
114115

@@ -124,7 +125,7 @@ main() {
124125

125126
test("ignores the encoding", () {
126127
var asset = new Asset.fromString(id, "contents");
127-
expect(asset.readAsString(encoding: Encoding.ISO_8859_1),
128+
expect(asset.readAsString(encoding: LATIN1),
128129
completion(equals("contents")));
129130
});
130131
});

pkg/barback/test/utils.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ library barback.test.utils;
66

77
import 'dart:async';
88
import 'dart:collection';
9+
import 'dart:convert' show Encoding;
910
import 'dart:io';
1011

1112
import 'package:barback/barback.dart';

pkg/http/lib/src/byte_stream.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library byte_stream;
66

77
import 'dart:async';
8+
import 'dart:convert';
89
import 'dart:io';
910
import 'dart:typed_data';
1011

@@ -30,10 +31,10 @@ class ByteStream extends StreamView<List<int>> {
3031
}
3132

3233
/// Collect the data of this stream in a [String], decoded according to
33-
/// [encoding], which defaults to `Encoding.UTF_8`.
34-
Future<String> bytesToString([Encoding encoding=Encoding.UTF_8]) =>
35-
toBytes().then((bytes) => decodeString(bytes, encoding));
34+
/// [encoding], which defaults to `UTF8`.
35+
Future<String> bytesToString([Encoding encoding=UTF8]) =>
36+
toBytes().then((bytes) => encoding.decode(bytes));
3637

37-
Stream<String> toStringStream([Encoding encoding=Encoding.UTF_8]) =>
38-
transform(new StringDecoder(encoding));
38+
Stream<String> toStringStream([Encoding encoding=UTF8]) =>
39+
transform(encoding.decoder);
3940
}

pkg/http/lib/src/multipart_file.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library multipart_file;
66

77
import 'dart:async';
8+
import 'dart:convert';
89
import 'dart:io';
910

1011
import 'package:path/path.dart' as path;
@@ -70,14 +71,14 @@ class MultipartFile {
7071
contentType = contentType == null ? new ContentType("text", "plain")
7172
: contentType;
7273
var charset = contentType.charset;
73-
var encoding = encodingForCharset(contentType.charset, Encoding.UTF_8);
74+
var encoding = encodingForCharset(contentType.charset, UTF8);
7475
// Make a new contentType with ensured charset.
7576
contentType = new ContentType(contentType.primaryType,
7677
contentType.subType,
7778
charset: encoding.name,
7879
parameters: contentType.parameters);
7980

80-
return new MultipartFile.fromBytes(field, encodeString(value, encoding),
81+
return new MultipartFile.fromBytes(field, encoding.encode(value),
8182
filename: filename,
8283
contentType: contentType);
8384
}

pkg/http/lib/src/request.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
library request;
66

7+
import 'dart:convert';
78
import 'dart:io';
89
import 'dart:typed_data';
910

@@ -36,7 +37,7 @@ class Request extends BaseRequest {
3637
/// If the request has a `Content-Type` header and that header has a `charset`
3738
/// parameter, that parameter's value is used as the encoding. Otherwise, if
3839
/// [encoding] has been set manually, that encoding is used. If that hasn't
39-
/// been set either, this defaults to [Encoding.UTF_8].
40+
/// been set either, this defaults to [UTF8].
4041
///
4142
/// If the `charset` parameter's value is not a known [Encoding], reading this
4243
/// will throw a [FormatException].
@@ -83,10 +84,10 @@ class Request extends BaseRequest {
8384
/// header, one will be added with the type `text/plain`. Then the `charset`
8485
/// parameter of the `Content-Type` header (whether new or pre-existing) will
8586
/// be set to [encoding] if it wasn't already set.
86-
String get body => decodeString(bodyBytes, encoding);
87+
String get body => encoding.decode(bodyBytes);
8788

8889
set body(String value) {
89-
bodyBytes = encodeString(value, encoding);
90+
bodyBytes = encoding.encode(value);
9091
var contentType = _contentType;
9192
if (contentType == null) {
9293
contentType = new ContentType("text", "plain", charset: encoding.name);
@@ -137,7 +138,7 @@ class Request extends BaseRequest {
137138
/// Creates a new HTTP request.
138139
Request(String method, Uri url)
139140
: super(method, url),
140-
_defaultEncoding = Encoding.UTF_8,
141+
_defaultEncoding = UTF8,
141142
_bodyBytes = new Uint8List(0);
142143

143144
/// Freezes all mutable fields and returns a single-subscription [ByteStream]

pkg/http/lib/src/response.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
library response;
66

77
import 'dart:async';
8+
import 'dart:convert';
89
import 'dart:io';
910
import 'dart:typed_data';
1011

@@ -21,10 +22,10 @@ class Response extends BaseResponse {
2122
/// The body of the response as a string. This is converted from [bodyBytes]
2223
/// using the `charset` parameter of the `Content-Type` header field, if
2324
/// available. If it's unavailable or if the encoding name is unknown,
24-
/// [Encoding.ISO_8859_1] is used by default, as per [RFC 2616][].
25+
/// [LATIN1] is used by default, as per [RFC 2616][].
2526
///
2627
/// [RFC 2616]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html
27-
String get body => decodeString(bodyBytes, _encodingForHeaders(headers));
28+
String get body => _encodingForHeaders(headers).decode(bodyBytes);
2829

2930
/// Creates a new HTTP response with a string body.
3031
Response(
@@ -36,7 +37,7 @@ class Response extends BaseResponse {
3637
bool persistentConnection: true,
3738
String reasonPhrase})
3839
: this.bytes(
39-
encodeString(body, _encodingForHeaders(headers)),
40+
_encodingForHeaders(headers).encode(body),
4041
statusCode,
4142
request: request,
4243
headers: headers,
@@ -80,7 +81,7 @@ class Response extends BaseResponse {
8081
}
8182

8283
/// Returns the encoding to use for a response with the given headers. This
83-
/// defaults to [Encoding.ISO_8859_1] if the headers don't specify a charset or
84+
/// defaults to [LATIN1] if the headers don't specify a charset or
8485
/// if that charset is unknown.
8586
Encoding _encodingForHeaders(Map<String, String> headers) =>
8687
encodingForCharset(_contentTypeForHeaders(headers).charset);

pkg/http/lib/src/utils.dart

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
library utils;
66

77
import 'dart:async';
8+
import 'dart:convert';
89
import 'dart:io';
910
import 'dart:typed_data';
10-
import 'dart:utf';
1111

1212
import 'byte_stream.dart';
1313

@@ -66,9 +66,9 @@ List<String> split1(String toSplit, String pattern) {
6666
/// [charset] is null or if no [Encoding] was found that corresponds to
6767
/// [charset].
6868
Encoding encodingForCharset(
69-
String charset, [Encoding fallback = Encoding.ISO_8859_1]) {
69+
String charset, [Encoding fallback = LATIN1]) {
7070
if (charset == null) return fallback;
71-
var encoding = Encoding.fromName(charset);
71+
var encoding = Encoding.getByName(charset);
7272
return encoding == null ? fallback : encoding;
7373
}
7474

@@ -77,23 +77,11 @@ Encoding encodingForCharset(
7777
/// [FormatException] if no [Encoding] was found that corresponds to [charset].
7878
/// [charset] may not be null.
7979
Encoding requiredEncodingForCharset(String charset) {
80-
var encoding = Encoding.fromName(charset);
80+
var encoding = Encoding.getByName(charset);
8181
if (encoding != null) return encoding;
8282
throw new FormatException('Unsupported encoding "$charset".');
8383
}
8484

85-
/// Converts [bytes] into a [String] according to [encoding].
86-
String decodeString(List<int> bytes, Encoding encoding) {
87-
// TODO(nweiz): implement this once issue 6284 is fixed.
88-
return decodeUtf8(bytes);
89-
}
90-
91-
/// Converts [string] into a byte array according to [encoding].
92-
List<int> encodeString(String string, Encoding encoding) {
93-
// TODO(nweiz): implement this once issue 6284 is fixed.
94-
return encodeUtf8(string);
95-
}
96-
9785
/// A regular expression that matches strings that are composed entirely of
9886
/// ASCII-compatible characters.
9987
final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$");

pkg/http/test/request_test.dart

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
library request_test;
66

7+
import 'dart:convert';
78
import 'dart:io';
89

910
import 'package:http/http.dart' as http;
@@ -62,32 +63,32 @@ void main() {
6263
group('#encoding', () {
6364
test('defaults to utf-8', () {
6465
var request = new http.Request('POST', dummyUrl);
65-
expect(request.encoding.name, equals(Encoding.UTF_8.name));
66+
expect(request.encoding.name, equals(UTF8.name));
6667
});
6768

6869
test('can be set', () {
6970
var request = new http.Request('POST', dummyUrl);
70-
request.encoding = Encoding.ISO_8859_1;
71-
expect(request.encoding.name, equals(Encoding.ISO_8859_1.name));
71+
request.encoding = LATIN1;
72+
expect(request.encoding.name, equals(LATIN1.name));
7273
});
7374

7475
test('is based on the content-type charset if it exists', () {
7576
var request = new http.Request('POST', dummyUrl);
7677
request.headers[HttpHeaders.CONTENT_TYPE] =
7778
'text/plain; charset=iso-8859-1';
78-
expect(request.encoding.name, equals(Encoding.ISO_8859_1.name));
79+
expect(request.encoding.name, equals(LATIN1.name));
7980
});
8081

8182
test('remains the default if the content-type charset is set and unset',
8283
() {
8384
var request = new http.Request('POST', dummyUrl);
84-
request.encoding = Encoding.ISO_8859_1;
85+
request.encoding = LATIN1;
8586
request.headers[HttpHeaders.CONTENT_TYPE] =
8687
'text/plain; charset=utf-8';
87-
expect(request.encoding.name, equals(Encoding.UTF_8.name));
88+
expect(request.encoding.name, equals(UTF8.name));
8889

8990
request.headers.remove(HttpHeaders.CONTENT_TYPE);
90-
expect(request.encoding.name, equals(Encoding.ISO_8859_1.name));
91+
expect(request.encoding.name, equals(LATIN1.name));
9192
});
9293

9394
test('throws an error if the content-type charset is unknown', () {
@@ -240,7 +241,7 @@ void main() {
240241

241242
test('defaults to empty if only encoding is set', () {
242243
var request = new http.Request('POST', dummyUrl);
243-
request.encoding = Encoding.ISO_8859_1;
244+
request.encoding = LATIN1;
244245
expect(request.headers[HttpHeaders.CONTENT_TYPE], isNull);
245246
});
246247

@@ -255,7 +256,7 @@ void main() {
255256
test('is set to application/x-www-form-urlencoded with the given charset '
256257
'if bodyFields and encoding are set', () {
257258
var request = new http.Request('POST', dummyUrl);
258-
request.encoding = Encoding.ISO_8859_1;
259+
request.encoding = LATIN1;
259260
request.bodyFields = {'hello': 'world'};
260261
expect(request.headers[HttpHeaders.CONTENT_TYPE],
261262
equals('application/x-www-form-urlencoded; charset=iso-8859-1'));
@@ -264,7 +265,7 @@ void main() {
264265
test('is set to text/plain and the given encoding if body and encoding are '
265266
'both set', () {
266267
var request = new http.Request('POST', dummyUrl);
267-
request.encoding = Encoding.ISO_8859_1;
268+
request.encoding = LATIN1;
268269
request.body = 'hello, world';
269270
expect(request.headers[HttpHeaders.CONTENT_TYPE],
270271
equals('text/plain; charset=iso-8859-1'));
@@ -281,7 +282,7 @@ void main() {
281282
test('is modified to include the given encoding if encoding is set', () {
282283
var request = new http.Request('POST', dummyUrl);
283284
request.headers[HttpHeaders.CONTENT_TYPE] = 'application/json';
284-
request.encoding = Encoding.ISO_8859_1;
285+
request.encoding = LATIN1;
285286
expect(request.headers[HttpHeaders.CONTENT_TYPE],
286287
equals('application/json; charset=iso-8859-1'));
287288
});
@@ -290,7 +291,7 @@ void main() {
290291
var request = new http.Request('POST', dummyUrl);
291292
request.headers[HttpHeaders.CONTENT_TYPE] =
292293
'application/json; charset=utf-8';
293-
request.encoding = Encoding.ISO_8859_1;
294+
request.encoding = LATIN1;
294295
expect(request.headers[HttpHeaders.CONTENT_TYPE],
295296
equals('application/json; charset=iso-8859-1'));
296297
});
@@ -350,8 +351,8 @@ void main() {
350351
var request = new http.Request('POST', dummyUrl);
351352
request.finalize();
352353

353-
expect(request.encoding.name, equals(Encoding.UTF_8.name));
354-
expect(() => request.encoding = Encoding.ASCII, throwsStateError);
354+
expect(request.encoding.name, equals(UTF8.name));
355+
expect(() => request.encoding = ASCII, throwsStateError);
355356
});
356357

357358
test('freezes #bodyBytes', () {

0 commit comments

Comments
 (0)