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

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

Issue 20372002: Ignore all trailing separators in path.extension. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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/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 bb88953f36c0f2e13c25d46ade9ab8d6e3184835..4b87cde6309d6c7109162424b13da4b441ec8933 100644
--- a/pkg/path/lib/path.dart
+++ b/pkg/path/lib/path.dart
@@ -1043,7 +1043,8 @@ class _ParsedPath {
/// path ends with a trailing separator.
List<String> separators;
- /// The file extension of the last part, or "" if it doesn't have one.
+ /// The file extension of the last non-empty part, or "" if it doesn't have
+ /// one.
String get extension => _splitExtension()[1];
/// `true` if this is an absolute path.
@@ -1059,12 +1060,7 @@ class _ParsedPath {
return copy.parts.last;
}
- String get basenameWithoutExtension {
- var copy = this.clone();
- copy.removeTrailingSeparators();
- if (copy.parts.isEmpty) return root == null ? '' : root;
- return copy._splitExtension()[0];
- }
+ String get basenameWithoutExtension => _splitExtension()[0];
bool get hasTrailingSeparator =>
!parts.isEmpty && (parts.last == '' || separators.last != '');
@@ -1137,13 +1133,15 @@ class _ParsedPath {
return builder.toString();
}
- /// Splits the last part of the path into a two-element list. The first is
- /// the name of the file without any extension. The second is the extension
- /// or "" if it has none.
+ /// Splits the last non-empty part of the path into a `[basename, extension`]
+ /// pair.
+ ///
+ /// Returns a two-element list. The first is the name of the file without any
+ /// extension. The second is the extension or "" if it has none.
List<String> _splitExtension() {
- if (parts.isEmpty) return ['', ''];
+ var file = parts.lastWhere((p) => p != '', orElse: () => null);
- var file = parts.last;
+ if (file == null) return ['', ''];
if (file == '..') return ['..', ''];
var lastDot = file.lastIndexOf('.');
« no previous file with comments | « no previous file | pkg/path/test/posix_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698