1
+ /*
2
+ * Copyright 2002-2009 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
1
17
package org .springframework .util ;
2
18
3
19
import java .util .Map ;
4
20
5
21
/**
6
- * Package-protected helper class for {@link AntPathMatcher}. Tests whether or not a string matches against a pattern.
7
- * The pattern may contain special characters:<br> '*' means zero or more characters<br> '?' means one and only one
8
- * character, '{' and '}' indicate a uri template pattern
22
+ * Package-protected helper class for {@link AntPathMatcher}.
23
+ * Tests whether or not a string matches against a pattern.
24
+ *
25
+ * <p>The pattern may contain special characters: '*' means zero or more characters;
26
+ * '?' means one and only one character; '{' and '}' indicate a URI template pattern.
9
27
*
10
28
* @author Arjen Poutsma
11
29
* @since 3.0
@@ -28,29 +46,24 @@ class AntPatchStringMatcher {
28
46
29
47
private final Map <String , String > uriTemplateVariables ;
30
48
31
- /** Constructs a new instance of the <code>AntPatchStringMatcher</code>. */
32
- AntPatchStringMatcher (String pattern , String str , Map <String , String > uriTemplateVariables ) {
33
- patArr = pattern .toCharArray ();
34
- strArr = str .toCharArray ();
49
+
50
+ /**
51
+ * Construct a new instance of the <code>AntPatchStringMatcher</code>.
52
+ */
53
+ public AntPatchStringMatcher (String pattern , String str , Map <String , String > uriTemplateVariables ) {
54
+ this .patArr = pattern .toCharArray ();
55
+ this .strArr = str .toCharArray ();
56
+ this .patIdxEnd = this .patArr .length - 1 ;
57
+ this .strIdxEnd = this .strArr .length - 1 ;
35
58
this .uriTemplateVariables = uriTemplateVariables ;
36
- patIdxEnd = patArr .length - 1 ;
37
- strIdxEnd = strArr .length - 1 ;
38
59
}
39
60
40
- private void addTemplateVariable (int curlyIdxStart , int curlyIdxEnd , int valIdxStart , int valIdxEnd ) {
41
- if (uriTemplateVariables != null ) {
42
- String varName = new String (patArr , curlyIdxStart + 1 , curlyIdxEnd - curlyIdxStart - 1 );
43
- String varValue = new String (strArr , valIdxStart , valIdxEnd - valIdxStart + 1 );
44
- uriTemplateVariables .put (varName , varValue );
45
- }
46
- }
47
61
48
62
/**
49
63
* Main entry point.
50
- *
51
64
* @return <code>true</code> if the string matches against the pattern, or <code>false</code> otherwise.
52
65
*/
53
- boolean matchStrings () {
66
+ public boolean matchStrings () {
54
67
if (shortcutPossible ()) {
55
68
return doShortcut ();
56
69
}
@@ -119,6 +132,14 @@ boolean matchStrings() {
119
132
return onlyStarsLeft ();
120
133
}
121
134
135
+ private void addTemplateVariable (int curlyIdxStart , int curlyIdxEnd , int valIdxStart , int valIdxEnd ) {
136
+ if (uriTemplateVariables != null ) {
137
+ String varName = new String (patArr , curlyIdxStart + 1 , curlyIdxEnd - curlyIdxStart - 1 );
138
+ String varValue = new String (strArr , valIdxStart , valIdxEnd - valIdxStart + 1 );
139
+ uriTemplateVariables .put (varName , varValue );
140
+ }
141
+ }
142
+
122
143
private boolean consecutiveStars (int patIdxTmp ) {
123
144
if (patIdxTmp == patIdxStart + 1 && patArr [patIdxStart ] == '*' && patArr [patIdxTmp ] == '*' ) {
124
145
// Two stars next to each other, skip the first one.
0 commit comments