Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/utils.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/utils.dart b/sdk/lib/_internal/pub/lib/src/utils.dart |
| index acca0bb05e1aadd90997945551b6ff88607f9233..4c5d6b44a0a057f02fada6da08fde677c1d4f861 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/utils.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/utils.dart |
| @@ -101,6 +101,16 @@ String toSentence(Iterable iter) { |
| return iter.take(iter.length - 1).join(", ") + " and ${iter.last}"; |
| } |
| +/// Returns [name] if [number] is 1, or the plural of [name] otherwise. |
| +/// |
| +/// By default, this just adds "s" to the end of [name] to get the plural. If |
| +/// [plural] is passed, that's used instead. |
| +String pluralize(String name, int number, {String plural}) { |
| + if (number == 1) return name; |
| + if (plural != null) return plural; |
| + return '${name}s'; |
| +} |
| + |
| /// Flattens nested lists inside an iterable into a single list containing only |
| /// non-list elements. |
| List flatten(Iterable nested) { |
| @@ -118,16 +128,6 @@ List flatten(Iterable nested) { |
| return result; |
| } |
| -/// Asserts that [iter] contains only one element, and returns it. |
| -only(Iterable iter) { |
| - var iterator = iter.iterator; |
| - var currentIsValid = iterator.moveNext(); |
| - assert(currentIsValid); |
| - var obj = iterator.current; |
| - assert(!iterator.moveNext()); |
| - return obj; |
| -} |
| - |
| /// Returns a set containing all elements in [minuend] that are not in |
| /// [subtrahend]. |
| Set setMinus(Iterable minuend, Iterable subtrahend) { |
| @@ -506,6 +506,18 @@ Uri canonicalizeUri(Uri uri) { |
| return uri; |
| } |
| +/// Returns a human-friendly representation of [inputPath]. |
| +/// |
| +/// If [inputPath] isn't too distant from the current working directory, this |
| +/// will return the relative path to it. Otherwise, it will return the absolute |
| +/// path. |
| +String nicePath(String inputPath) { |
| + var relative = path.relative(inputPath); |
| + var split = path.split(relative); |
| + if (split[0] == '..' && split[1] == '..') return path.absolute(inputPath); |
|
Bob Nystrom
2013/09/23 17:11:22
Need to make sure split has length > 1 first.
nweiz
2013/09/23 22:06:10
Done.
|
| + return relative; |
| +} |
| + |
| /// Decodes a URL-encoded string. Unlike [Uri.decodeComponent], this includes |
| /// replacing `+` with ` `. |
| String urlDecode(String encoded) => |