Skip to content

Commit 8ea20f7

Browse files
committed
Cleanup
1 parent ada4c08 commit 8ea20f7

File tree

1 file changed

+4
-100
lines changed

1 file changed

+4
-100
lines changed

lib/src/utils.dart

Lines changed: 4 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:async';
65
import 'dart:convert';
7-
import 'dart:typed_data';
86

97
import 'package:collection/collection.dart';
108

@@ -29,107 +27,13 @@ Map<K, V> updateMap<K, V>(Map<K, V> original, Map<K, V> updates) {
2927
/// //=> "foo=bar&baz=bang"
3028
String mapToQuery(Map<String, String> map, {Encoding encoding}) {
3129
var pairs = <List<String>>[];
32-
map.forEach((key, value) =>
33-
pairs.add([Uri.encodeQueryComponent(key, encoding: encoding),
34-
Uri.encodeQueryComponent(value, encoding: encoding)]));
30+
map.forEach((key, value) => pairs.add([
31+
Uri.encodeQueryComponent(key, encoding: encoding),
32+
Uri.encodeQueryComponent(value, encoding: encoding)
33+
]));
3534
return pairs.map((pair) => "${pair[0]}=${pair[1]}").join("&");
3635
}
3736

38-
/// Like [String.split], but only splits on the first occurrence of the pattern.
39-
/// This will always return an array of two elements or fewer.
40-
///
41-
/// split1("foo,bar,baz", ","); //=> ["foo", "bar,baz"]
42-
/// split1("foo", ","); //=> ["foo"]
43-
/// split1("", ","); //=> []
44-
List<String> split1(String toSplit, String pattern) {
45-
if (toSplit.isEmpty) return <String>[];
46-
47-
var index = toSplit.indexOf(pattern);
48-
if (index == -1) return [toSplit];
49-
return [
50-
toSplit.substring(0, index),
51-
toSplit.substring(index + pattern.length)
52-
];
53-
}
54-
55-
56-
/// A regular expression that matches strings that are composed entirely of
57-
/// ASCII-compatible characters.
58-
final RegExp _ASCII_ONLY = new RegExp(r"^[\x00-\x7F]+$");
59-
60-
/// Returns whether [string] is composed entirely of ASCII-compatible
61-
/// characters.
62-
bool isPlainAscii(String string) => _ASCII_ONLY.hasMatch(string);
63-
64-
/// Converts [input] into a [Uint8List].
65-
///
66-
/// If [input] is a [TypedData], this just returns a view on [input].
67-
Uint8List toUint8List(List<int> input) {
68-
if (input is Uint8List) return input;
69-
if (input is TypedData) {
70-
// TODO(nweiz): remove "as" when issue 11080 is fixed.
71-
return new Uint8List.view((input as TypedData).buffer);
72-
}
73-
return new Uint8List.fromList(input);
74-
}
75-
76-
/// Calls [onDone] once [stream] (a single-subscription [Stream]) is finished.
77-
/// The return value, also a single-subscription [Stream] should be used in
78-
/// place of [stream] after calling this method.
79-
Stream<T> onDone<T>(Stream<T> stream, void onDone()) =>
80-
stream.transform(new StreamTransformer.fromHandlers(handleDone: (sink) {
81-
sink.close();
82-
onDone();
83-
}));
84-
85-
// TODO(nweiz): remove this when issue 7786 is fixed.
86-
/// Pipes all data and errors from [stream] into [sink]. When [stream] is done,
87-
/// [sink] is closed and the returned [Future] is completed.
88-
Future store(Stream stream, EventSink sink) {
89-
var completer = new Completer();
90-
stream.listen(sink.add,
91-
onError: sink.addError,
92-
onDone: () {
93-
sink.close();
94-
completer.complete();
95-
});
96-
return completer.future;
97-
}
98-
99-
/// Pipes all data and errors from [stream] into [sink]. Completes [Future] once
100-
/// [stream] is done. Unlike [store], [sink] remains open after [stream] is
101-
/// done.
102-
Future writeStreamToSink(Stream stream, EventSink sink) {
103-
var completer = new Completer();
104-
stream.listen(sink.add,
105-
onError: sink.addError,
106-
onDone: () => completer.complete());
107-
return completer.future;
108-
}
109-
110-
/// A pair of values.
111-
class Pair<E, F> {
112-
E first;
113-
F last;
114-
115-
Pair(this.first, this.last);
116-
117-
String toString() => '($first, $last)';
118-
119-
bool operator==(other) {
120-
if (other is! Pair) return false;
121-
return other.first == first && other.last == last;
122-
}
123-
124-
int get hashCode => first.hashCode ^ last.hashCode;
125-
}
126-
127-
/// Configures [future] so that its result (success or exception) is passed on
128-
/// to [completer].
129-
void chainToCompleter(Future future, Completer completer) {
130-
future.then(completer.complete, onError: completer.completeError);
131-
}
132-
13337
/// Returns the header with the given [name] in [headers].
13438
///
13539
/// This works even if [headers] is `null`, or if it's not yet a

0 commit comments

Comments
 (0)