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

Side by Side Diff: pkg/path/lib/src/context.dart

Issue 439223002: Add InternalStyle:rootLength to implement isAbsolute and rootPrefix. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review update. Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library path.context; 5 library path.context;
6 6
7 import 'internal_style.dart'; 7 import 'internal_style.dart';
8 import 'style.dart'; 8 import 'style.dart';
9 import 'parsed_path.dart'; 9 import 'parsed_path.dart';
10 import 'path_exception.dart'; 10 import 'path_exception.dart';
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 /// context.rootPrefix('/path/to/foo'); // -> '/' 141 /// context.rootPrefix('/path/to/foo'); // -> '/'
142 /// 142 ///
143 /// // Windows 143 /// // Windows
144 /// context.rootPrefix(r'path\to\foo'); // -> '' 144 /// context.rootPrefix(r'path\to\foo'); // -> ''
145 /// context.rootPrefix(r'C:\path\to\foo'); // -> r'C:\' 145 /// context.rootPrefix(r'C:\path\to\foo'); // -> r'C:\'
146 /// 146 ///
147 /// // URL 147 /// // URL
148 /// context.rootPrefix('path/to/foo'); // -> '' 148 /// context.rootPrefix('path/to/foo'); // -> ''
149 /// context.rootPrefix('http://dartlang.org/path/to/foo'); 149 /// context.rootPrefix('http://dartlang.org/path/to/foo');
150 /// // -> 'http://dartlang.org' 150 /// // -> 'http://dartlang.org'
151 String rootPrefix(String path) { 151 String rootPrefix(String path) => path.substring(0, style.rootLength(path));
152 var root = _parse(path).root;
153 return root == null ? '' : root;
154 }
155 152
156 /// Returns `true` if [path] is an absolute path and `false` if it is a 153 /// Returns `true` if [path] is an absolute path and `false` if it is a
157 /// relative path. 154 /// relative path.
158 /// 155 ///
159 /// On POSIX systems, absolute paths start with a `/` (forward slash). On 156 /// On POSIX systems, absolute paths start with a `/` (forward slash). On
160 /// Windows, an absolute path starts with `\\`, or a drive letter followed by 157 /// Windows, an absolute path starts with `\\`, or a drive letter followed by
161 /// `:/` or `:\`. For URLs, absolute paths either start with a protocol and 158 /// `:/` or `:\`. For URLs, absolute paths either start with a protocol and
162 /// optional hostname (e.g. `http://dartlang.org`, `file://`) or with a `/`. 159 /// optional hostname (e.g. `http://dartlang.org`, `file://`) or with a `/`.
163 /// 160 ///
164 /// URLs that start with `/` are known as "root-relative", since they're 161 /// URLs that start with `/` are known as "root-relative", since they're
165 /// relative to the root of the current URL. Since root-relative paths are 162 /// relative to the root of the current URL. Since root-relative paths are
166 /// still absolute in every other sense, [isAbsolute] will return true for 163 /// still absolute in every other sense, [isAbsolute] will return true for
167 /// them. They can be detected using [isRootRelative]. 164 /// them. They can be detected using [isRootRelative].
168 bool isAbsolute(String path) => _parse(path).isAbsolute; 165 bool isAbsolute(String path) => style.rootLength(path) > 0;
169 166
170 /// Returns `true` if [path] is a relative path and `false` if it is absolute. 167 /// Returns `true` if [path] is a relative path and `false` if it is absolute.
171 /// On POSIX systems, absolute paths start with a `/` (forward slash). On 168 /// On POSIX systems, absolute paths start with a `/` (forward slash). On
172 /// Windows, an absolute path starts with `\\`, or a drive letter followed by 169 /// Windows, an absolute path starts with `\\`, or a drive letter followed by
173 /// `:/` or `:\`. 170 /// `:/` or `:\`.
174 bool isRelative(String path) => !this.isAbsolute(path); 171 bool isRelative(String path) => !this.isAbsolute(path);
175 172
176 /// Returns `true` if [path] is a root-relative path and `false` if it's not. 173 /// Returns `true` if [path] is a root-relative path and `false` if it's not.
177 /// 174 ///
178 /// URLs that start with `/` are known as "root-relative", since they're 175 /// URLs that start with `/` are known as "root-relative", since they're
179 /// relative to the root of the current URL. Since root-relative paths are 176 /// relative to the root of the current URL. Since root-relative paths are
180 /// still absolute in every other sense, [isAbsolute] will return true for 177 /// still absolute in every other sense, [isAbsolute] will return true for
181 /// them. They can be detected using [isRootRelative]. 178 /// them. They can be detected using [isRootRelative].
182 /// 179 ///
183 /// No POSIX and Windows paths are root-relative. 180 /// No POSIX and Windows paths are root-relative.
184 bool isRootRelative(String path) => _parse(path).isRootRelative; 181 bool isRootRelative(String path) => style.isRootRelative(path);
185 182
186 /// Joins the given path parts into a single path. Example: 183 /// Joins the given path parts into a single path. Example:
187 /// 184 ///
188 /// context.join('path', 'to', 'foo'); // -> 'path/to/foo' 185 /// context.join('path', 'to', 'foo'); // -> 'path/to/foo'
189 /// 186 ///
190 /// If any part ends in a path separator, then a redundant separator will not 187 /// If any part ends in a path separator, then a redundant separator will not
191 /// be added: 188 /// be added:
192 /// 189 ///
193 /// context.join('path/', 'to', 'foo'); // -> 'path/to/foo 190 /// context.join('path/', 'to', 'foo'); // -> 'path/to/foo
194 /// 191 ///
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 // Show the arguments. 544 // Show the arguments.
548 var message = new StringBuffer(); 545 var message = new StringBuffer();
549 message.write("$method("); 546 message.write("$method(");
550 message.write(args.take(numArgs) 547 message.write(args.take(numArgs)
551 .map((arg) => arg == null ? "null" : '"$arg"') 548 .map((arg) => arg == null ? "null" : '"$arg"')
552 .join(", ")); 549 .join(", "));
553 message.write("): part ${i - 1} was null, but part $i was not."); 550 message.write("): part ${i - 1} was null, but part $i was not.");
554 throw new ArgumentError(message.toString()); 551 throw new ArgumentError(message.toString());
555 } 552 }
556 } 553 }
OLDNEW
« no previous file with comments | « no previous file | pkg/path/lib/src/internal_style.dart » ('j') | pkg/path/lib/src/internal_style.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698