@@ -9,6 +9,34 @@ library engine.utilities.dart;
9
9
10
10
import 'java_core.dart' ;
11
11
12
+ /**
13
+ * Check whether [uri1] starts with (or 'is prefixed by') [uri2] by checking
14
+ * path segments.
15
+ */
16
+ bool startsWith (Uri uri1, Uri uri2) {
17
+ List <String > uri1Segments = uri1.pathSegments;
18
+ List <String > uri2Segments = uri2.pathSegments.toList ();
19
+ // Punt if empty (https://github.com/dart-lang/sdk/issues/24126)
20
+ if (uri2Segments.isEmpty) {
21
+ return false ;
22
+ }
23
+ // Trim trailing empty segments ('/foo/' => ['foo', ''])
24
+ if (uri2Segments.last == '' ) {
25
+ uri2Segments.removeLast ();
26
+ }
27
+
28
+ if (uri2Segments.length > uri1Segments.length) {
29
+ return false ;
30
+ }
31
+
32
+ for (int i = 0 ; i < uri2Segments.length; ++ i) {
33
+ if (uri2Segments[i] != uri1Segments[i]) {
34
+ return false ;
35
+ }
36
+ }
37
+ return true ;
38
+ }
39
+
12
40
/**
13
41
* The enumeration `ParameterKind` defines the different kinds of parameters. There are two
14
42
* basic kinds of parameters: required and optional. Optional parameters are further divided into
@@ -38,27 +66,3 @@ class ParameterKind extends Enum<ParameterKind> {
38
66
const ParameterKind (String name, int ordinal, this .isOptional)
39
67
: super (name, ordinal);
40
68
}
41
-
42
- /**
43
- * Check whether [uri1] starts with (or 'is prefixed by') [uri2] by checking
44
- * path segments.
45
- */
46
- bool startsWith (Uri uri1, Uri uri2) {
47
- List <String > uri1Segments = uri1.pathSegments;
48
- List <String > uri2Segments = uri2.pathSegments.toList ();
49
- // Trim trailing empty segments ('/foo/' => ['foo', ''])
50
- if (uri2Segments.last == '' ) {
51
- uri2Segments.removeLast ();
52
- }
53
-
54
- if (uri2Segments.length > uri1Segments.length) {
55
- return false ;
56
- }
57
-
58
- for (int i = 0 ; i < uri2Segments.length; ++ i) {
59
- if (uri2Segments[i] != uri1Segments[i]) {
60
- return false ;
61
- }
62
- }
63
- return true ;
64
- }
0 commit comments