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

Side by Side Diff: pkg/path/lib/src/style/url.dart

Issue 812253002: Delete a bunch of packages that are now on GitHub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Un-delete http Created 6 years 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/src/style/posix.dart ('k') | pkg/path/lib/src/style/windows.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library path.style.url;
6
7 import '../characters.dart' as chars;
8 import '../internal_style.dart';
9 import '../utils.dart';
10
11 /// The style for URL paths.
12 class UrlStyle extends InternalStyle {
13 UrlStyle();
14
15 final name = 'url';
16 final separator = '/';
17 final separators = const ['/'];
18
19 // Deprecated properties.
20
21 final separatorPattern = new RegExp(r'/');
22 final needsSeparatorPattern = new RegExp(
23 r"(^[a-zA-Z][-+.a-zA-Z\d]*://|[^/])$");
24 final rootPattern = new RegExp(r"[a-zA-Z][-+.a-zA-Z\d]*://[^/]*");
25 final relativeRootPattern = new RegExp(r"^/");
26
27 bool containsSeparator(String path) => path.contains('/');
28
29 bool isSeparator(int codeUnit) => codeUnit == chars.SLASH;
30
31 bool needsSeparator(String path) {
32 if (path.isEmpty) return false;
33
34 // A URL that doesn't end in "/" always needs a separator.
35 if (!isSeparator(path.codeUnitAt(path.length - 1))) return true;
36
37 // A URI that's just "scheme://" needs an extra separator, despite ending
38 // with "/".
39 return path.endsWith("://") && rootLength(path) == path.length;
40 }
41
42 int rootLength(String path) {
43 if (path.isEmpty) return 0;
44 if (isSeparator(path.codeUnitAt(0))) return 1;
45 var index = path.indexOf("/");
46 if (index > 0 && path.startsWith('://', index - 1)) {
47 // The root part is up until the next '/', or the full path. Skip
48 // '://' and search for '/' after that.
49 index = path.indexOf('/', index + 2);
50 if (index > 0) return index;
51 return path.length;
52 }
53 return 0;
54 }
55
56 bool isRootRelative(String path) =>
57 path.isNotEmpty && isSeparator(path.codeUnitAt(0));
58
59 String getRelativeRoot(String path) => isRootRelative(path) ? '/' : null;
60
61 String pathFromUri(Uri uri) => uri.toString();
62
63 Uri relativePathToUri(String path) => Uri.parse(path);
64 Uri absolutePathToUri(String path) => Uri.parse(path);
65 }
OLDNEW
« no previous file with comments | « pkg/path/lib/src/style/posix.dart ('k') | pkg/path/lib/src/style/windows.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698