OLD | NEW |
| (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; | |
6 | |
7 import 'context.dart'; | |
8 import 'style/posix.dart'; | |
9 import 'style/url.dart'; | |
10 import 'style/windows.dart'; | |
11 | |
12 /// An enum type describing a "flavor" of path. | |
13 abstract class Style { | |
14 /// POSIX-style paths use "/" (forward slash) as separators. Absolute paths | |
15 /// start with "/". Used by UNIX, Linux, Mac OS X, and others. | |
16 static final Style posix = new PosixStyle(); | |
17 | |
18 /// Windows paths use "\" (backslash) as separators. Absolute paths start with | |
19 /// a drive letter followed by a colon (example, "C:") or two backslashes | |
20 /// ("\\") for UNC paths. | |
21 // TODO(rnystrom): The UNC root prefix should include the drive name too, not | |
22 // just the "\\". | |
23 static final Style windows = new WindowsStyle(); | |
24 | |
25 /// URLs aren't filesystem paths, but they're supported to make it easier to | |
26 /// manipulate URL paths in the browser. | |
27 /// | |
28 /// URLs use "/" (forward slash) as separators. Absolute paths either start | |
29 /// with a protocol and optional hostname (e.g. `http://dartlang.org`, | |
30 /// `file://`) or with "/". | |
31 static final Style url = new UrlStyle(); | |
32 | |
33 /// The style of the host platform. | |
34 /// | |
35 /// When running on the command line, this will be [windows] or [posix] based | |
36 /// on the host operating system. On a browser, this will be [url]. | |
37 static final Style platform = _getPlatformStyle(); | |
38 | |
39 /// Gets the type of the host platform. | |
40 static Style _getPlatformStyle() { | |
41 // If we're running a Dart file in the browser from a `file:` URI, | |
42 // [Uri.base] will point to a file. If we're running on the standalone, | |
43 // it will point to a directory. We can use that fact to determine which | |
44 // style to use. | |
45 if (Uri.base.scheme != 'file') return Style.url; | |
46 if (!Uri.base.path.endsWith('/')) return Style.url; | |
47 if (new Uri(path: 'a/b').toFilePath() == 'a\\b') return Style.windows; | |
48 return Style.posix; | |
49 } | |
50 | |
51 /// The name of this path style. Will be "posix" or "windows". | |
52 String get name; | |
53 | |
54 /// A [Context] that uses this style. | |
55 Context get context => new Context(style: this); | |
56 | |
57 @Deprecated("Most Style members will be removed in path 2.0.") | |
58 String get separator; | |
59 | |
60 @Deprecated("Most Style members will be removed in path 2.0.") | |
61 Pattern get separatorPattern; | |
62 | |
63 @Deprecated("Most Style members will be removed in path 2.0.") | |
64 Pattern get needsSeparatorPattern; | |
65 | |
66 @Deprecated("Most Style members will be removed in path 2.0.") | |
67 Pattern get rootPattern; | |
68 | |
69 @Deprecated("Most Style members will be removed in path 2.0.") | |
70 Pattern get relativeRootPattern; | |
71 | |
72 @Deprecated("Most style members will be removed in path 2.0.") | |
73 String getRoot(String path); | |
74 | |
75 @Deprecated("Most style members will be removed in path 2.0.") | |
76 String getRelativeRoot(String path); | |
77 | |
78 @Deprecated("Most style members will be removed in path 2.0.") | |
79 String pathFromUri(Uri uri); | |
80 | |
81 @Deprecated("Most style members will be removed in path 2.0.") | |
82 Uri relativePathToUri(String path); | |
83 | |
84 @Deprecated("Most style members will be removed in path 2.0.") | |
85 Uri absolutePathToUri(String path); | |
86 | |
87 String toString() => name; | |
88 } | |
OLD | NEW |