| OLD | NEW |
| 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.style; | 5 library path.style; |
| 6 | 6 |
| 7 import 'context.dart'; | 7 import 'context.dart'; |
| 8 import 'style/posix.dart'; | 8 import 'style/posix.dart'; |
| 9 import 'style/url.dart'; | 9 import 'style/url.dart'; |
| 10 import 'style/windows.dart'; | 10 import 'style/windows.dart'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // style to use. | 44 // style to use. |
| 45 if (Uri.base.scheme != 'file') return Style.url; | 45 if (Uri.base.scheme != 'file') return Style.url; |
| 46 if (!Uri.base.path.endsWith('/')) 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; | 47 if (new Uri(path: 'a/b').toFilePath() == 'a\\b') return Style.windows; |
| 48 return Style.posix; | 48 return Style.posix; |
| 49 } | 49 } |
| 50 | 50 |
| 51 /// The name of this path style. Will be "posix" or "windows". | 51 /// The name of this path style. Will be "posix" or "windows". |
| 52 String get name; | 52 String get name; |
| 53 | 53 |
| 54 /// The path separator for this style. On POSIX, this is `/`. On Windows, | |
| 55 /// it's `\`. | |
| 56 String get separator; | |
| 57 | |
| 58 /// The [Pattern] that can be used to match a separator for a path in this | |
| 59 /// style. Windows allows both "/" and "\" as path separators even though "\" | |
| 60 /// is the canonical one. | |
| 61 Pattern get separatorPattern; | |
| 62 | |
| 63 /// The [Pattern] that matches path components that need a separator after | |
| 64 /// them. | |
| 65 /// | |
| 66 /// Windows and POSIX styles just need separators when the previous component | |
| 67 /// doesn't already end in a separator, but the URL always needs to place a | |
| 68 /// separator between the root and the first component, even if the root | |
| 69 /// already ends in a separator character. For example, to join "file://" and | |
| 70 /// "usr", an additional "/" is needed (making "file:///usr"). | |
| 71 Pattern get needsSeparatorPattern; | |
| 72 | |
| 73 /// The [Pattern] that can be used to match the root prefix of an absolute | |
| 74 /// path in this style. | |
| 75 Pattern get rootPattern; | |
| 76 | |
| 77 /// The [Pattern] that can be used to match the root prefix of a root-relative | |
| 78 /// path in this style. | |
| 79 /// | |
| 80 /// This can be null to indicate that this style doesn't support root-relative | |
| 81 /// paths. | |
| 82 final Pattern relativeRootPattern = null; | |
| 83 | |
| 84 /// A [Context] that uses this style. | 54 /// A [Context] that uses this style. |
| 85 Context get context => new Context(style: this); | 55 Context get context => new Context(style: this); |
| 86 | 56 |
| 87 /// Gets the root prefix of [path] if path is absolute. If [path] is relative, | 57 @Deprecated("Most Style members will be removed in path 2.0.") |
| 88 /// returns `null`. | 58 String get separator; |
| 89 String getRoot(String path) { | |
| 90 // TODO(rnystrom): Use firstMatch() when #7080 is fixed. | |
| 91 var matches = rootPattern.allMatches(path); | |
| 92 if (matches.isNotEmpty) return matches.first[0]; | |
| 93 return getRelativeRoot(path); | |
| 94 } | |
| 95 | 59 |
| 96 /// Gets the root prefix of [path] if it's root-relative. | 60 @Deprecated("Most Style members will be removed in path 2.0.") |
| 97 /// | 61 Pattern get separatorPattern; |
| 98 /// If [path] is relative or absolute and not root-relative, returns `null`. | |
| 99 String getRelativeRoot(String path) { | |
| 100 if (relativeRootPattern == null) return null; | |
| 101 // TODO(rnystrom): Use firstMatch() when #7080 is fixed. | |
| 102 var matches = relativeRootPattern.allMatches(path); | |
| 103 if (matches.isEmpty) return null; | |
| 104 return matches.first[0]; | |
| 105 } | |
| 106 | 62 |
| 107 /// Returns the path represented by [uri] in this style. | 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.") |
| 108 String pathFromUri(Uri uri); | 79 String pathFromUri(Uri uri); |
| 109 | 80 |
| 110 /// Returns the URI that represents the relative path made of [parts]. | 81 @Deprecated("Most style members will be removed in path 2.0.") |
| 111 Uri relativePathToUri(String path) => | 82 Uri relativePathToUri(String path); |
| 112 new Uri(pathSegments: context.split(path)); | |
| 113 | 83 |
| 114 /// Returns the URI that represents [path], which is assumed to be absolute. | 84 @Deprecated("Most style members will be removed in path 2.0.") |
| 115 Uri absolutePathToUri(String path); | 85 Uri absolutePathToUri(String path); |
| 116 | 86 |
| 117 String toString() => name; | 87 String toString() => name; |
| 118 } | 88 } |
| OLD | NEW |