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

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

Issue 203673003: Allow [path.fromUri] to take a string as well as a URI. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 9 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
« no previous file with comments | « pkg/path/lib/path.dart ('k') | pkg/path/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'style.dart'; 7 import 'style.dart';
8 import 'parsed_path.dart'; 8 import 'parsed_path.dart';
9 import 'path_exception.dart'; 9 import 'path_exception.dart';
10 import '../path.dart' as p; 10 import '../path.dart' as p;
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 for (var i = parsed.parts.length - 1; i >= 0; i--) { 416 for (var i = parsed.parts.length - 1; i >= 0; i--) {
417 if (!parsed.parts[i].isEmpty) { 417 if (!parsed.parts[i].isEmpty) {
418 parsed.parts[i] = parsed.basenameWithoutExtension; 418 parsed.parts[i] = parsed.basenameWithoutExtension;
419 break; 419 break;
420 } 420 }
421 } 421 }
422 422
423 return parsed.toString(); 423 return parsed.toString();
424 } 424 }
425 425
426 /// Returns the path represented by [uri]. 426 /// Returns the path represented by [uri], which may be a [String] or a [Uri].
427 /// 427 ///
428 /// For POSIX and Windows styles, [uri] must be a `file:` URI. For the URL 428 /// For POSIX and Windows styles, [uri] must be a `file:` URI. For the URL
429 /// style, this will just convert [uri] to a string. 429 /// style, this will just convert [uri] to a string.
430 /// 430 ///
431 /// // POSIX 431 /// // POSIX
432 /// context.fromUri(Uri.parse('file:///path/to/foo')) 432 /// context.fromUri('file:///path/to/foo')
433 /// // -> '/path/to/foo' 433 /// // -> '/path/to/foo'
434 /// 434 ///
435 /// // Windows 435 /// // Windows
436 /// context.fromUri(Uri.parse('file:///C:/path/to/foo')) 436 /// context.fromUri('file:///C:/path/to/foo')
437 /// // -> r'C:\path\to\foo' 437 /// // -> r'C:\path\to\foo'
438 /// 438 ///
439 /// // URL 439 /// // URL
440 /// context.fromUri(Uri.parse('http://dartlang.org/path/to/foo')) 440 /// context.fromUri('http://dartlang.org/path/to/foo')
441 /// // -> 'http://dartlang.org/path/to/foo' 441 /// // -> 'http://dartlang.org/path/to/foo'
442 String fromUri(Uri uri) => style.pathFromUri(uri); 442 ///
443 /// If [uri] is relative, a relative path will be returned.
444 ///
445 /// path.fromUri('path/to/foo'); // -> 'path/to/foo'
446 String fromUri(uri) {
447 if (uri is String) uri = Uri.parse(uri);
448 return style.pathFromUri(uri);
449 }
443 450
444 /// Returns the URI that represents [path]. 451 /// Returns the URI that represents [path].
445 /// 452 ///
446 /// For POSIX and Windows styles, this will return a `file:` URI. For the URL 453 /// For POSIX and Windows styles, this will return a `file:` URI. For the URL
447 /// style, this will just convert [path] to a [Uri]. 454 /// style, this will just convert [path] to a [Uri].
448 /// 455 ///
449 /// // POSIX 456 /// // POSIX
450 /// context.toUri('/path/to/foo') 457 /// context.toUri('/path/to/foo')
451 /// // -> Uri.parse('file:///path/to/foo') 458 /// // -> Uri.parse('file:///path/to/foo')
452 /// 459 ///
(...skipping 30 matching lines...) Expand all
483 // Show the arguments. 490 // Show the arguments.
484 var message = new StringBuffer(); 491 var message = new StringBuffer();
485 message.write("$method("); 492 message.write("$method(");
486 message.write(args.take(numArgs) 493 message.write(args.take(numArgs)
487 .map((arg) => arg == null ? "null" : '"$arg"') 494 .map((arg) => arg == null ? "null" : '"$arg"')
488 .join(", ")); 495 .join(", "));
489 message.write("): part ${i - 1} was null, but part $i was not."); 496 message.write("): part ${i - 1} was null, but part $i was not.");
490 throw new ArgumentError(message.toString()); 497 throw new ArgumentError(message.toString());
491 } 498 }
492 } 499 }
OLDNEW
« no previous file with comments | « pkg/path/lib/path.dart ('k') | pkg/path/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698