Skip to content

Commit d7e4375

Browse files
authored
Cleanup package:http utils (#1011)
1 parent eafbbb0 commit d7e4375

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

pkgs/http/lib/src/utils.dart

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ import 'byte_stream.dart';
1212
///
1313
/// mapToQuery({"foo": "bar", "baz": "bang"});
1414
/// //=> "foo=bar&baz=bang"
15-
String mapToQuery(Map<String, String> map, {Encoding? encoding}) {
16-
var pairs = <List<String>>[];
17-
map.forEach((key, value) => pairs.add([
18-
Uri.encodeQueryComponent(key, encoding: encoding ?? utf8),
19-
Uri.encodeQueryComponent(value, encoding: encoding ?? utf8)
20-
]));
21-
return pairs.map((pair) => '${pair[0]}=${pair[1]}').join('&');
22-
}
15+
String mapToQuery(Map<String, String> map, {required Encoding encoding}) =>
16+
map.entries
17+
.map((e) => '${Uri.encodeQueryComponent(e.key, encoding: encoding)}'
18+
'=${Uri.encodeQueryComponent(e.value, encoding: encoding)}')
19+
.join('&');
2320

2421
/// Returns the [Encoding] that corresponds to [charset].
2522
///
@@ -34,8 +31,6 @@ Encoding encodingForCharset(String? charset, [Encoding fallback = latin1]) {
3431
///
3532
/// Throws a [FormatException] if no [Encoding] was found that corresponds to
3633
/// [charset].
37-
///
38-
/// [charset] may not be null.
3934
Encoding requiredEncodingForCharset(String charset) =>
4035
Encoding.getByName(charset) ??
4136
(throw FormatException('Unsupported encoding "$charset".'));
@@ -53,9 +48,8 @@ bool isPlainAscii(String string) => _asciiOnly.hasMatch(string);
5348
/// If [input] is a [TypedData], this just returns a view on [input].
5449
Uint8List toUint8List(List<int> input) {
5550
if (input is Uint8List) return input;
56-
if (input is TypedData) {
57-
// TODO(nweiz): remove "as" when issue 11080 is fixed.
58-
return Uint8List.view((input as TypedData).buffer);
51+
if (input case TypedData data) {
52+
return Uint8List.view(data.buffer);
5953
}
6054
return Uint8List.fromList(input);
6155
}

0 commit comments

Comments
 (0)