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 location; | 5 library location; |
6 | 6 |
7 import 'package:observe/observe.dart'; | 7 import 'package:observe/observe.dart'; |
8 | 8 |
9 // These regular expressions are not strictly accurate for picking Dart | 9 // These regular expressions are not strictly accurate for picking Dart |
10 // identifiers out of arbitrary text, e.g. identifiers must start with an | 10 // identifiers out of arbitrary text, e.g. identifiers must start with an |
(...skipping 20 matching lines...) Expand all Loading... | |
31 /// link which is to a method on the same page as its class. So, e.g. | 31 /// link which is to a method on the same page as its class. So, e.g. |
32 /// in `dart-core.Object@id_noSuchMethod,invocation` this separates | 32 /// in `dart-core.Object@id_noSuchMethod,invocation` this separates |
33 /// the method `noSuchMethod` from the parameter `invocation`. | 33 /// the method `noSuchMethod` from the parameter `invocation`. |
34 const PARAMETER_SEPARATOR = ","; | 34 const PARAMETER_SEPARATOR = ","; |
35 | 35 |
36 /// The character used to separate the class name from the constructor | 36 /// The character used to separate the class name from the constructor |
37 /// name, e.g. `Future.Future-delayed`. Will occur by itself for | 37 /// name, e.g. `Future.Future-delayed`. Will occur by itself for |
38 /// an unnamed constructor. e.g. `Future.Future-` | 38 /// an unnamed constructor. e.g. `Future.Future-` |
39 const CONSTRUCTOR_SEPARATOR = "-"; | 39 const CONSTRUCTOR_SEPARATOR = "-"; |
40 | 40 |
41 /// The prefix to be used for anchors. This is here so that we can easily | |
42 /// factor it out into being #! and use the _escaped_fragment_ scheme | |
43 /// for providing static versions of pages if we get them. | |
Emily Fortuna
2014/02/04 01:47:51
is there some link explaining the "escaped fragmen
Alan Knight
2014/02/04 18:08:14
Done.
| |
44 const AJAX_LOCATION_PREFIX = "#!"; | |
45 const BASIC_LOCATION_PREFIX = "#"; | |
46 | |
47 // Prefix the string with the separator we are using between the main | |
48 // URL and the location. | |
49 locationPrefixed(String s) => "$BASIC_LOCATION_PREFIX$s"; | |
50 | |
51 // Remove the anchor prefix from [s] if it's present. | |
52 locationDeprefixed(String s) { | |
53 if (s.startsWith(AJAX_LOCATION_PREFIX)) { | |
54 return s.substring(AJAX_LOCATION_PREFIX.length, s.length); | |
55 } else if (s.startsWith(BASIC_LOCATION_PREFIX)) { | |
56 return s.substring(BASIC_LOCATION_PREFIX.length, s.length); | |
57 } else { | |
58 return s; | |
59 } | |
60 } | |
61 | |
41 // This represents a component described by a URI and can give us | 62 // This represents a component described by a URI and can give us |
42 // the URI given the component or vice versa. | 63 // the URI given the component or vice versa. |
43 class DocsLocation { | 64 class DocsLocation { |
44 String packageName; | 65 String packageName; |
45 String libraryName; | 66 String libraryName; |
46 String memberName; | 67 String memberName; |
47 String subMemberName; | 68 String subMemberName; |
48 String anchor; | 69 String anchor; |
49 | 70 |
50 // TODO(alanknight): These might be nicer to work with as immutable value | 71 // TODO(alanknight): These might be nicer to work with as immutable value |
(...skipping 30 matching lines...) Expand all Loading... | |
81 } | 102 } |
82 | 103 |
83 /// This isn't a particularly good hash code, but we don't really hash | 104 /// This isn't a particularly good hash code, but we don't really hash |
84 /// these very much. Just XOR together all the fields. | 105 /// these very much. Just XOR together all the fields. |
85 int get hashCode => packageName.hashCode ^ libraryName.hashCode ^ | 106 int get hashCode => packageName.hashCode ^ libraryName.hashCode ^ |
86 memberName.hashCode ^ subMemberName.hashCode ^ anchor.hashCode; | 107 memberName.hashCode ^ subMemberName.hashCode ^ anchor.hashCode; |
87 | 108 |
88 void _extractPieces(String uri) { | 109 void _extractPieces(String uri) { |
89 | 110 |
90 if (uri == null || uri.length == 0) return; | 111 if (uri == null || uri.length == 0) return; |
91 var position = (uri[0] == "#") ? 1 : 0; | 112 var position = uri.startsWith(AJAX_LOCATION_PREFIX) ? AJAX_LOCATION_PREFIX.l ength : 0; |
Emily Fortuna
2014/02/04 01:47:51
80 char
Alan Knight
2014/02/04 18:08:14
Done.
| |
92 | 113 |
93 _check(regex) { | 114 _check(regex) { |
94 var match = regex.matchAsPrefix(uri, position); | 115 var match = regex.matchAsPrefix(uri, position); |
95 if (match != null) { | 116 if (match != null) { |
96 var matchedString = match.group(1); | 117 var matchedString = match.group(1); |
97 position = position + match.group(0).length; | 118 position = position + match.group(0).length; |
98 return matchedString; | 119 return matchedString; |
99 } | 120 } |
100 } | 121 } |
101 | 122 |
102 packageName = _check(packageMatch); | 123 packageName = _check(packageMatch); |
103 libraryName = _check(libraryMatch); | 124 libraryName = _check(libraryMatch); |
104 memberName = _check(memberMatch); | 125 memberName = _check(memberMatch); |
105 subMemberName = _check(subMemberMatch); | 126 subMemberName = _check(subMemberMatch); |
106 anchor = _check(anchorMatch); | 127 anchor = _check(anchorMatch); |
107 if (position < uri.length && anchor == null) { | 128 if (position < uri.length && anchor == null) { |
108 // allow an anchor that's just dotted, not @ if we don't find an @ | 129 // allow an anchor that's just dotted, not @ if we don't find an @ |
109 // form and we haven't reached the end. | 130 // form and we haven't reached the end. |
110 anchor = uri.substring(position + 1, uri.length); | 131 anchor = uri.substring(position + 1, uri.length); |
111 } | 132 } |
112 } | 133 } |
113 | 134 |
114 /// The URI hash string without its leading hash | 135 /// The URI hash string without its leading hash |
115 /// and without any trailing anchor portion, e.g. for | 136 /// and without any trailing anchor portion, e.g. for |
116 /// http://site/#args/args.ArgParser#id_== it would return args/argsArgParser | 137 /// http://site/#args/args.ArgParser@id_== it would return args/argsArgParser |
117 @reflectable String get withoutAnchor => | 138 @reflectable String get withoutAnchor => |
118 [packagePlus, libraryPlus, memberPlus, subMemberPlus].join(""); | 139 [packagePlus, libraryPlus, memberPlus, subMemberPlus].join(""); |
119 | 140 |
120 /// The URI hash for just the library portion of this location. | 141 /// The URI hash for just the library portion of this location. |
121 @reflectable String get libraryQualifiedName => "$packagePlus$libraryPlus"; | 142 @reflectable String get libraryQualifiedName => "$packagePlus$libraryPlus"; |
122 | 143 |
123 /// The full URI hash string without the leading hash character. | 144 /// The full URI hash string without the leading hash character. |
124 /// e.g. for | 145 /// e.g. for |
125 /// http://site/#args/args.ArgParser#id_== | 146 /// http://site/#args/args.ArgParser@id_== |
126 /// it would return args/argsArgParser#id_== | 147 /// it would return args/argsArgParser@id_== |
127 @reflectable String get withAnchor => withoutAnchor + anchorPlus; | 148 @reflectable String get withAnchor => withoutAnchor + anchorPlus; |
128 | 149 |
129 @reflectable DocsLocation get locationWithoutAnchor => | 150 @reflectable DocsLocation get locationWithoutAnchor => |
130 new DocsLocation.clone(this)..anchor = null; | 151 new DocsLocation.clone(this)..anchor = null; |
131 | 152 |
132 /// The package name with the trailing / separator, or the empty | 153 /// The package name with the trailing / separator, or the empty |
133 /// string if the package name is not set. | 154 /// string if the package name is not set. |
134 @reflectable get packagePlus => packageName == null | 155 @reflectable get packagePlus => packageName == null |
135 ? '' | 156 ? '' |
136 : libraryName == null | 157 : libraryName == null |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 if (anchor != null) return anchor; | 353 if (anchor != null) return anchor; |
333 if (subMemberName != null) return subMemberName; | 354 if (subMemberName != null) return subMemberName; |
334 if (memberName != null) return memberName; | 355 if (memberName != null) return memberName; |
335 if (libraryName != null) return libraryName; | 356 if (libraryName != null) return libraryName; |
336 if (packageName != null) return packageName; | 357 if (packageName != null) return packageName; |
337 return null; | 358 return null; |
338 } | 359 } |
339 | 360 |
340 @reflectable toString() => 'DocsLocation($withAnchor)'; | 361 @reflectable toString() => 'DocsLocation($withAnchor)'; |
341 } | 362 } |
OLD | NEW |