| Index: sdk/lib/_internal/pub_generated/lib/src/utils.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/utils.dart b/sdk/lib/_internal/pub_generated/lib/src/utils.dart
|
| similarity index 92%
|
| copy from sdk/lib/_internal/pub/lib/src/utils.dart
|
| copy to sdk/lib/_internal/pub_generated/lib/src/utils.dart
|
| index 09575d7bf8e9e54d733ade12dfd87f3ab9adfc47..d03db2a4d724b9b5839f5c12debb3c46f52aebd3 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/utils.dart
|
| +++ b/sdk/lib/_internal/pub_generated/lib/src/utils.dart
|
| @@ -32,7 +32,7 @@ class Pair<E, F> {
|
|
|
| String toString() => '($first, $last)';
|
|
|
| - bool operator==(other) {
|
| + bool operator ==(other) {
|
| if (other is! Pair) return false;
|
| return other.first == first && other.last == last;
|
| }
|
| @@ -95,8 +95,8 @@ Future newFuture(callback()) => new Future.value().then((_) => callback());
|
| Future captureErrors(Future callback(), {bool captureStackChains: false}) {
|
| var completer = new Completer();
|
| var wrappedCallback = () {
|
| - new Future.sync(callback).then(completer.complete)
|
| - .catchError((e, stackTrace) {
|
| + new Future.sync(
|
| + callback).then(completer.complete).catchError((e, stackTrace) {
|
| // [stackTrace] can be null if we're running without [captureStackChains],
|
| // since dart:io will often throw errors without stack traces.
|
| if (stackTrace != null) {
|
| @@ -305,8 +305,7 @@ minBy(Iterable iter, Comparable f(element)) {
|
| var minComparable = null;
|
| for (var element in iter) {
|
| var comparable = f(element);
|
| - if (minComparable == null ||
|
| - comparable.compareTo(minComparable) < 0) {
|
| + if (minComparable == null || comparable.compareTo(minComparable) < 0) {
|
| min = element;
|
| minComparable = comparable;
|
| }
|
| @@ -346,17 +345,17 @@ Map mapMap(Map map, {key(key, value), value(key, value)}) {
|
| }
|
|
|
| /// Like [Map.fromIterable], but [key] and [value] may return [Future]s.
|
| -Future<Map> mapFromIterableAsync(Iterable iter, {key(element),
|
| - value(element)}) {
|
| +Future<Map> mapFromIterableAsync(Iterable iter, {key(element), value(element)})
|
| + {
|
| if (key == null) key = (element) => element;
|
| if (value == null) value = (element) => element;
|
|
|
| var map = new Map();
|
| return Future.wait(iter.map((element) {
|
| - return Future.wait([
|
| - new Future.sync(() => key(element)),
|
| - new Future.sync(() => value(element))
|
| - ]).then((results) {
|
| + return Future.wait(
|
| + [
|
| + new Future.sync(() => key(element)),
|
| + new Future.sync(() => value(element))]).then((results) {
|
| map[results[0]] = results[1];
|
| });
|
| })).then((_) => map);
|
| @@ -410,7 +409,10 @@ Set<String> createDirectoryFilter(Iterable<String> dirs) {
|
| return dirs.expand((dir) {
|
| var result = ["/$dir/"];
|
| if (Platform.operatingSystem == 'windows') {
|
| - result..add("/$dir\\")..add("\\$dir/")..add("\\$dir\\");
|
| + result
|
| + ..add("/$dir\\")
|
| + ..add("\\$dir/")
|
| + ..add("\\$dir\\");
|
| }
|
| return result;
|
| }).toSet();
|
| @@ -421,8 +423,8 @@ Set<String> createDirectoryFilter(Iterable<String> dirs) {
|
| /// [compare] defaults to [Comparable.compare].
|
| maxAll(Iterable iter, [int compare(element1, element2)]) {
|
| if (compare == null) compare = Comparable.compare;
|
| - return iter.reduce((max, element) =>
|
| - compare(element, max) > 0 ? element : max);
|
| + return iter.reduce(
|
| + (max, element) => compare(element, max) > 0 ? element : max);
|
| }
|
|
|
| /// Returns the minimum value in [iter] by [compare].
|
| @@ -430,8 +432,8 @@ maxAll(Iterable iter, [int compare(element1, element2)]) {
|
| /// [compare] defaults to [Comparable.compare].
|
| minAll(Iterable iter, [int compare(element1, element2)]) {
|
| if (compare == null) compare = Comparable.compare;
|
| - return iter.reduce((max, element) =>
|
| - compare(element, max) < 0 ? element : max);
|
| + return iter.reduce(
|
| + (max, element) => compare(element, max) < 0 ? element : max);
|
| }
|
|
|
| /// Replace each instance of [matcher] in [source] with the return value of
|
| @@ -533,10 +535,11 @@ Future streamFirst(Stream stream) {
|
| /// Returns a wrapped version of [stream] along with a [StreamSubscription] that
|
| /// can be used to control the wrapped stream.
|
| Pair<Stream, StreamSubscription> streamWithSubscription(Stream stream) {
|
| - var controller =
|
| - stream.isBroadcast ? new StreamController.broadcast(sync: true)
|
| - : new StreamController(sync: true);
|
| - var subscription = stream.listen(controller.add,
|
| + var controller = stream.isBroadcast ?
|
| + new StreamController.broadcast(sync: true) :
|
| + new StreamController(sync: true);
|
| + var subscription = stream.listen(
|
| + controller.add,
|
| onError: controller.addError,
|
| onDone: controller.close);
|
| return new Pair<Stream, StreamSubscription>(controller.stream, subscription);
|
| @@ -571,10 +574,7 @@ Stream mergeStreams(Stream stream1, Stream stream2) {
|
| var controller = new StreamController(sync: true);
|
|
|
| for (var stream in [stream1, stream2]) {
|
| - stream.listen(
|
| - controller.add,
|
| - onError: controller.addError,
|
| - onDone: () {
|
| + stream.listen(controller.add, onError: controller.addError, onDone: () {
|
| doneCount++;
|
| if (doneCount == 2) controller.close();
|
| });
|
| @@ -590,7 +590,7 @@ final _trailingCR = new RegExp(r"\r$");
|
| // fixed.
|
| /// Splits [text] on its line breaks in a Windows-line-break-friendly way.
|
| List<String> splitLines(String text) =>
|
| - text.split("\n").map((line) => line.replaceFirst(_trailingCR, "")).toList();
|
| + text.split("\n").map((line) => line.replaceFirst(_trailingCR, "")).toList();
|
|
|
| /// Converts a stream of arbitrarily chunked strings into a line-by-line stream.
|
| ///
|
| @@ -598,25 +598,24 @@ List<String> splitLines(String text) =>
|
| /// newline is ignored.
|
| Stream<String> streamToLines(Stream<String> stream) {
|
| var buffer = new StringBuffer();
|
| - return stream.transform(new StreamTransformer.fromHandlers(
|
| - handleData: (chunk, sink) {
|
| - var lines = splitLines(chunk);
|
| - var leftover = lines.removeLast();
|
| - for (var line in lines) {
|
| - if (!buffer.isEmpty) {
|
| - buffer.write(line);
|
| - line = buffer.toString();
|
| - buffer = new StringBuffer();
|
| - }
|
| -
|
| - sink.add(line);
|
| - }
|
| - buffer.write(leftover);
|
| - },
|
| - handleDone: (sink) {
|
| - if (!buffer.isEmpty) sink.add(buffer.toString());
|
| - sink.close();
|
| - }));
|
| + return stream.transform(
|
| + new StreamTransformer.fromHandlers(handleData: (chunk, sink) {
|
| + var lines = splitLines(chunk);
|
| + var leftover = lines.removeLast();
|
| + for (var line in lines) {
|
| + if (!buffer.isEmpty) {
|
| + buffer.write(line);
|
| + line = buffer.toString();
|
| + buffer = new StringBuffer();
|
| + }
|
| +
|
| + sink.add(line);
|
| + }
|
| + buffer.write(leftover);
|
| + }, handleDone: (sink) {
|
| + if (!buffer.isEmpty) sink.add(buffer.toString());
|
| + sink.close();
|
| + }));
|
| }
|
|
|
| /// Like [Iterable.where], but allows [test] to return [Future]s and uses the
|
| @@ -626,9 +625,10 @@ Future<Iterable> futureWhere(Iterable iter, test(value)) {
|
| var result = test(e);
|
| if (result is! Future) result = new Future.value(result);
|
| return result.then((result) => new Pair(e, result));
|
| - }))
|
| - .then((pairs) => pairs.where((pair) => pair.last))
|
| - .then((pairs) => pairs.map((pair) => pair.first));
|
| + })).then(
|
| + (pairs) =>
|
| + pairs.where(
|
| + (pair) => pair.last)).then((pairs) => pairs.map((pair) => pair.first));
|
| }
|
|
|
| // TODO(nweiz): unify the following functions with the utility functions in
|
| @@ -642,8 +642,9 @@ List<String> split1(String toSplit, String pattern) {
|
|
|
| var index = toSplit.indexOf(pattern);
|
| if (index == -1) return [toSplit];
|
| - return [toSplit.substring(0, index),
|
| - toSplit.substring(index + pattern.length)];
|
| + return [
|
| + toSplit.substring(0, index),
|
| + toSplit.substring(index + pattern.length)];
|
| }
|
|
|
| /// Adds additional query parameters to [url], overwriting the original
|
| @@ -673,8 +674,8 @@ String mapToQuery(Map<String, String> map) {
|
| var pairs = <List<String>>[];
|
| map.forEach((key, value) {
|
| key = Uri.encodeQueryComponent(key);
|
| - value = (value == null || value.isEmpty)
|
| - ? null : Uri.encodeQueryComponent(value);
|
| + value =
|
| + (value == null || value.isEmpty) ? null : Uri.encodeQueryComponent(value);
|
| pairs.add([key, value]);
|
| });
|
| return pairs.map((pair) {
|
| @@ -685,7 +686,7 @@ String mapToQuery(Map<String, String> map) {
|
|
|
| /// Returns the union of all elements in each set in [sets].
|
| Set unionAll(Iterable<Set> sets) =>
|
| - sets.fold(new Set(), (union, set) => union.union(set));
|
| + sets.fold(new Set(), (union, set) => union.union(set));
|
|
|
| // TODO(nweiz): remove this when issue 9068 has been fixed.
|
| /// Whether [uri1] and [uri2] are equal.
|
| @@ -693,7 +694,7 @@ Set unionAll(Iterable<Set> sets) =>
|
| /// This consider HTTP URIs to default to port 80, and HTTPs URIs to default to
|
| /// port 443.
|
| bool urisEqual(Uri uri1, Uri uri2) =>
|
| - canonicalizeUri(uri1) == canonicalizeUri(uri2);
|
| + canonicalizeUri(uri1) == canonicalizeUri(uri2);
|
|
|
| /// Return [uri] with redundant port information removed.
|
| Uri canonicalizeUri(Uri uri) {
|
| @@ -736,7 +737,7 @@ String niceDuration(Duration duration) {
|
| ///
|
| /// Unlike [Uri.decodeComponent], this includes replacing `+` with ` `.
|
| String urlDecode(String encoded) =>
|
| - Uri.decodeComponent(encoded.replaceAll("+", " "));
|
| + Uri.decodeComponent(encoded.replaceAll("+", " "));
|
|
|
| /// Takes a simple data structure (composed of [Map]s, [Iterable]s, scalar
|
| /// objects, and [Future]s) and recursively resolves all the [Future]s contained
|
| @@ -753,8 +754,7 @@ Future awaitObject(object) {
|
|
|
| var pairs = <Future<Pair>>[];
|
| object.forEach((key, value) {
|
| - pairs.add(awaitObject(value)
|
| - .then((resolved) => new Pair(key, resolved)));
|
| + pairs.add(awaitObject(value).then((resolved) => new Pair(key, resolved)));
|
| });
|
| return Future.wait(pairs).then((resolvedPairs) {
|
| var map = {};
|
| @@ -780,9 +780,10 @@ String libraryPath(String libraryName) {
|
| ///
|
| /// On Windows or when not printing to a terminal, only printable ASCII
|
| /// characters should be used.
|
| -bool get canUseSpecialChars => !runningAsTest &&
|
| - Platform.operatingSystem != 'windows' &&
|
| - stdioType(stdout) == StdioType.TERMINAL;
|
| +bool get canUseSpecialChars =>
|
| + !runningAsTest &&
|
| + Platform.operatingSystem != 'windows' &&
|
| + stdioType(stdout) == StdioType.TERMINAL;
|
|
|
| /// Gets a "special" string (ANSI escape or Unicode).
|
| ///
|
|
|