Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Unified Diff: sdk/lib/_internal/pub/lib/src/utils.dart

Issue 24246002: Lazily throw pubspec parsing exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..51ac099869abdd579b2f8ea9d7a75fba122f3fa8 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,20 @@ 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.length > 1 && split[0] == '..' && split[1] == '..') {
+ return path.absolute(inputPath);
+ }
+ return relative;
+}
+
/// Decodes a URL-encoded string. Unlike [Uri.decodeComponent], this includes
/// replacing `+` with ` `.
String urlDecode(String encoded) =>
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/source/path.dart ('k') | sdk/lib/_internal/pub/lib/src/validator/pubspec_field.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698