OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | |
6 // significant change. Please see the README file for more information. | |
7 | |
8 library engine.utilities.dart; | 5 library engine.utilities.dart; |
9 | 6 |
10 import 'java_core.dart'; | 7 import 'java_core.dart'; |
11 | 8 |
12 /** | 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 |
| 37 /** |
13 * The enumeration `ParameterKind` defines the different kinds of parameters. Th
ere are two | 38 * The enumeration `ParameterKind` defines the different kinds of parameters. Th
ere are two |
14 * basic kinds of parameters: required and optional. Optional parameters are fur
ther divided into | 39 * basic kinds of parameters: required and optional. Optional parameters are fur
ther divided into |
15 * two kinds: positional optional and named optional. | 40 * two kinds: positional optional and named optional. |
16 */ | 41 */ |
17 class ParameterKind extends Enum<ParameterKind> { | 42 class ParameterKind extends Enum<ParameterKind> { |
18 static const ParameterKind REQUIRED = | 43 static const ParameterKind REQUIRED = |
19 const ParameterKind('REQUIRED', 0, false); | 44 const ParameterKind('REQUIRED', 0, false); |
20 | 45 |
21 static const ParameterKind POSITIONAL = | 46 static const ParameterKind POSITIONAL = |
22 const ParameterKind('POSITIONAL', 1, true); | 47 const ParameterKind('POSITIONAL', 1, true); |
23 | 48 |
24 static const ParameterKind NAMED = const ParameterKind('NAMED', 2, true); | 49 static const ParameterKind NAMED = const ParameterKind('NAMED', 2, true); |
25 | 50 |
26 static const List<ParameterKind> values = const [REQUIRED, POSITIONAL, NAMED]; | 51 static const List<ParameterKind> values = const [REQUIRED, POSITIONAL, NAMED]; |
27 | 52 |
28 /** | 53 /** |
29 * A flag indicating whether this is an optional parameter. | 54 * A flag indicating whether this is an optional parameter. |
30 */ | 55 */ |
31 final bool isOptional; | 56 final bool isOptional; |
32 | 57 |
33 /** | 58 /** |
34 * Initialize a newly created kind with the given state. | 59 * Initialize a newly created kind with the given state. |
35 * | 60 * |
36 * @param isOptional `true` if this is an optional parameter | 61 * @param isOptional `true` if this is an optional parameter |
37 */ | 62 */ |
38 const ParameterKind(String name, int ordinal, this.isOptional) | 63 const ParameterKind(String name, int ordinal, this.isOptional) |
39 : super(name, ordinal); | 64 : super(name, ordinal); |
40 } | 65 } |
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 } | |
OLD | NEW |