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

Unified Diff: pkg/path/lib/path.dart

Issue 12314047: Add path.joinAll. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 10 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
« no previous file with comments | « no previous file | pkg/path/test/path_posix_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/path/lib/path.dart
diff --git a/pkg/path/lib/path.dart b/pkg/path/lib/path.dart
index 3bd23323b0345de558047b114a62a37f92c7b83b..9e540b2d80fd8912178f0bee20e22e19fb605f46 100644
--- a/pkg/path/lib/path.dart
+++ b/pkg/path/lib/path.dart
@@ -112,6 +112,23 @@ String join(String part1, [String part2, String part3, String part4,
String part5, String part6, String part7, String part8]) =>
_builder.join(part1, part2, part3, part4, part5, part6, part7, part8);
+/// Joins the given path parts into a single path using the current platform's
+/// [separator]. Example:
+///
+/// path.joinAll(['path', 'to', 'foo']); // -> 'path/to/foo'
+///
+/// If any part ends in a path separator, then a redundant separator will not
+/// be added:
+///
+/// path.joinAll(['path/', 'to', 'foo']); // -> 'path/to/foo
+///
+/// If a part is an absolute path, then anything before that will be ignored:
+///
+/// path.joinAll(['path', '/to', 'foo']); // -> '/to/foo'
+///
+/// For a fixed number of parts, [join] is usually terser.
+String joinAll(Iterable<String> parts) => _builder.joinAll(parts);
+
// TODO(nweiz): add a UNC example for Windows once issue 7323 is fixed.
/// Splits [path] into its components using the current platform's [separator].
///
@@ -321,15 +338,30 @@ class Builder {
///
String join(String part1, [String part2, String part3, String part4,
String part5, String part6, String part7, String part8]) {
- var buffer = new StringBuffer();
- var needsSeparator = false;
-
var parts = [part1, part2, part3, part4, part5, part6, part7, part8];
_validateArgList("join", parts);
+ return joinAll(parts.where((part) => part != null));
+ }
- for (var part in parts) {
- if (part == null) continue;
+ /// Joins the given path parts into a single path. Example:
+ ///
+ /// builder.joinAll(['path', 'to', 'foo']); // -> 'path/to/foo'
+ ///
+ /// If any part ends in a path separator, then a redundant separator will not
+ /// be added:
+ ///
+ /// builder.joinAll(['path/', 'to', 'foo']); // -> 'path/to/foo
+ ///
+ /// If a part is an absolute path, then anything before that will be ignored:
+ ///
+ /// builder.joinAll(['path', '/to', 'foo']); // -> '/to/foo'
+ ///
+ /// For a fixed number of parts, [join] is usually terser.
+ String joinAll(Iterable<String> parts) {
+ var buffer = new StringBuffer();
+ var needsSeparator = false;
+ for (var part in parts) {
if (this.isAbsolute(part)) {
// An absolute path discards everything before it.
buffer.clear();
« no previous file with comments | « no previous file | pkg/path/test/path_posix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698