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

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

Issue 309803003: Avoid using RegExps in path to work around issue 19090. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 6 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/src/context.dart ('k') | pkg/path/lib/src/parsed_path.dart » ('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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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.internal_style; 5 library path.internal_style;
6 6
7 import 'context.dart'; 7 import 'context.dart';
8 import 'style.dart'; 8 import 'style.dart';
9 9
10 /// The internal interface for the [Style] type. 10 /// The internal interface for the [Style] type.
11 /// 11 ///
12 /// Users should be able to pass around instances of [Style] like an enum, but 12 /// Users should be able to pass around instances of [Style] like an enum, but
13 /// the members that [Context] uses should be hidden from them. Those members 13 /// the members that [Context] uses should be hidden from them. Those members
14 /// are defined on this class instead. 14 /// are defined on this class instead.
15 abstract class InternalStyle extends Style { 15 abstract class InternalStyle extends Style {
16 /// The path separator for this style. On POSIX, this is `/`. On Windows, 16 /// The default path separator for this style.
17 /// it's `\`. 17 ///
18 /// On POSIX, this is `/`. On Windows, it's `\`.
18 String get separator; 19 String get separator;
19 20
20 /// The [Pattern] that can be used to match a separator for a path in this 21 /// Returns whether [path] contains a separator.
21 /// style. Windows allows both "/" and "\" as path separators even though "\" 22 bool containsSeparator(String path);
22 /// is the canonical one.
23 Pattern get separatorPattern;
24 23
25 /// The [Pattern] that matches path components that need a separator after 24 /// Returns whether [codeUnit] is the character code of a separator.
26 /// them. 25 bool isSeparator(int codeUnit);
26
27 /// Returns whether this path component needs a separator after it.
27 /// 28 ///
28 /// Windows and POSIX styles just need separators when the previous component 29 /// Windows and POSIX styles just need separators when the previous component
29 /// doesn't already end in a separator, but the URL always needs to place a 30 /// doesn't already end in a separator, but the URL always needs to place a
30 /// separator between the root and the first component, even if the root 31 /// separator between the root and the first component, even if the root
31 /// already ends in a separator character. For example, to join "file://" and 32 /// already ends in a separator character. For example, to join "file://" and
32 /// "usr", an additional "/" is needed (making "file:///usr"). 33 /// "usr", an additional "/" is needed (making "file:///usr").
33 Pattern get needsSeparatorPattern; 34 bool needsSeparator(String path);
34
35 /// The [Pattern] that can be used to match the root prefix of an absolute
36 /// path in this style.
37 Pattern get rootPattern;
38
39 /// The [Pattern] that can be used to match the root prefix of a root-relative
40 /// path in this style.
41 ///
42 /// This can be null to indicate that this style doesn't support root-relative
43 /// paths.
44 final Pattern relativeRootPattern = null;
45 35
46 /// Gets the root prefix of [path] if path is absolute. If [path] is relative, 36 /// Gets the root prefix of [path] if path is absolute. If [path] is relative,
47 /// returns `null`. 37 /// returns `null`.
48 String getRoot(String path) { 38 String getRoot(String path);
49 // TODO(rnystrom): Use firstMatch() when #7080 is fixed.
50 var matches = rootPattern.allMatches(path);
51 if (matches.isNotEmpty) return matches.first[0];
52 return getRelativeRoot(path);
53 }
54 39
55 /// Gets the root prefix of [path] if it's root-relative. 40 /// Gets the root prefix of [path] if it's root-relative.
56 /// 41 ///
57 /// If [path] is relative or absolute and not root-relative, returns `null`. 42 /// If [path] is relative or absolute and not root-relative, returns `null`.
58 String getRelativeRoot(String path) { 43 String getRelativeRoot(String path);
59 if (relativeRootPattern == null) return null;
60 // TODO(rnystrom): Use firstMatch() when #7080 is fixed.
61 var matches = relativeRootPattern.allMatches(path);
62 if (matches.isEmpty) return null;
63 return matches.first[0];
64 }
65 44
66 /// Returns the path represented by [uri] in this style. 45 /// Returns the path represented by [uri] in this style.
67 String pathFromUri(Uri uri); 46 String pathFromUri(Uri uri);
68 47
69 /// Returns the URI that represents the relative path made of [parts]. 48 /// Returns the URI that represents the relative path made of [parts].
70 Uri relativePathToUri(String path) => 49 Uri relativePathToUri(String path) =>
71 new Uri(pathSegments: context.split(path)); 50 new Uri(pathSegments: context.split(path));
72 51
73 /// Returns the URI that represents [path], which is assumed to be absolute. 52 /// Returns the URI that represents [path], which is assumed to be absolute.
74 Uri absolutePathToUri(String path); 53 Uri absolutePathToUri(String path);
75 } 54 }
OLDNEW
« no previous file with comments | « pkg/path/lib/src/context.dart ('k') | pkg/path/lib/src/parsed_path.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698