@@ -68,12 +68,24 @@ public final class StringUtils {
68
68
private static final String FNAME_CHARS_PAT =
69
69
"[a-zA-Z0-9_\\ -\\ .]" ;
70
70
71
- private static final Pattern FNAME_CHARS_ANYMATCH =
72
- Pattern .compile (FNAME_CHARS_PAT );
73
-
74
71
private static final Pattern FNAME_CHARS_STARTSMATCH =
75
72
Pattern .compile ("^" + FNAME_CHARS_PAT );
76
73
74
+ /**
75
+ * Matches one of the same possible characters as CommonPath.lexh's {FPath}:
76
+ * <pre>
77
+ * {@code
78
+ * [a-zA-Z0-9_\-\./]
79
+ * }
80
+ * </pre>
81
+ * (Edit above and paste below [in NetBeans] for easy String escaping.)
82
+ */
83
+ private static final String FPATH_CHAR_PAT =
84
+ "[a-zA-Z0-9_\\ -\\ ./]" ;
85
+
86
+ private static final Pattern FPATH_CHAR_STARTSMATCH =
87
+ Pattern .compile ("^" + FPATH_CHAR_PAT );
88
+
77
89
/**
78
90
* Matches one of the same¹ possible characters as Common.lexh's {URIChar}:
79
91
* <pre>
@@ -89,14 +101,11 @@ public final class StringUtils {
89
101
private static final String URI_CHARS_PAT =
90
102
"[a-zA-Z0-9\\ -\\ ._~%:/\\ ?\\ #\\ [\\ ]@!\\ $&\\ '\\ (\\ )\\ *\\ +,;=]" ;
91
103
92
- private static final Pattern URI_CHARS_ANYMATCH =
93
- Pattern .compile (URI_CHARS_PAT );
94
-
95
104
private static final Pattern URI_CHARS_STARTSMATCH =
96
105
Pattern .compile ("^" + URI_CHARS_PAT );
97
106
107
+ /** Private to enforce singleton */
98
108
private StringUtils () {
99
- // Only static utility methods
100
109
}
101
110
102
111
/**
@@ -195,39 +204,19 @@ public static int nthIndexOf(String str, String substr, int n) {
195
204
return pos ;
196
205
}
197
206
198
- /**
199
- * Determines if the {@code value} contains characters matching
200
- * Common.lexh's {FNameChar}.
201
- * @param value the input to test
202
- * @return true if {@code value} matches anywhere
203
- */
204
- public static boolean containsFnameChars (String value ) {
205
- return FNAME_CHARS_ANYMATCH .matcher (value ).matches ();
206
- }
207
-
208
207
/**
209
208
* Determines if the {@code value} starts with characters matching
210
- * Common .lexh's {FNameChar}.
209
+ * CommonPath .lexh's {FNameChar}.
211
210
* @param value the input to test
212
211
* @return true if {@code value} matches at its start
213
212
*/
214
213
public static boolean startsWithFnameChars (String value ) {
215
214
return FNAME_CHARS_STARTSMATCH .matcher (value ).matches ();
216
215
}
217
216
218
- /**
219
- * Determines if the {@code value} contains characters matching
220
- * RFC-3986 and Common.lexh's definitions for allowable URI characters.
221
- * @param value the input to test
222
- * @return true if {@code value} matches anywhere
223
- */
224
- public static boolean containsURIChars (String value ) {
225
- return URI_CHARS_ANYMATCH .matcher (value ).matches ();
226
- }
227
-
228
217
/**
229
218
* Determines if the {@code value} starts with characters matching
230
- * RFC-3986 and Common .lexh's definitions for allowable URI characters.
219
+ * RFC-3986 and CommonPath .lexh's definitions for allowable URI characters.
231
220
* @param value the input to test
232
221
* @return true if {@code value} matches at its start
233
222
*/
@@ -288,4 +277,14 @@ public static int patindexOf(String value, Pattern pattern) {
288
277
if (!m .find ()) return -1 ;
289
278
return m .start ();
290
279
}
280
+
281
+ /**
282
+ * Determines if the {@code value} starts with a character in
283
+ * CommonPath.lexh's {FPath}.
284
+ * @param value the input to test
285
+ * @return true if {@code value} matches at its start
286
+ */
287
+ public static boolean startsWithFpathChar (String value ) {
288
+ return FPATH_CHAR_STARTSMATCH .matcher (value ).matches ();
289
+ }
291
290
}
0 commit comments