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