Skip to content

Commit 75c33dc

Browse files
committed
Add StringUtils.startsWithFpathChar(String)
1 parent 18d1c1c commit 75c33dc

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

src/org/opensolaris/opengrok/util/StringUtils.java

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,24 @@ public final class StringUtils {
6868
private static final String FNAME_CHARS_PAT =
6969
"[a-zA-Z0-9_\\-\\.]";
7070

71-
private static final Pattern FNAME_CHARS_ANYMATCH =
72-
Pattern.compile(FNAME_CHARS_PAT);
73-
7471
private static final Pattern FNAME_CHARS_STARTSMATCH =
7572
Pattern.compile("^" + FNAME_CHARS_PAT);
7673

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+
7789
/**
7890
* Matches one of the same¹ possible characters as Common.lexh's {URIChar}:
7991
* <pre>
@@ -89,14 +101,11 @@ public final class StringUtils {
89101
private static final String URI_CHARS_PAT =
90102
"[a-zA-Z0-9\\-\\._~%:/\\?\\#\\[\\]@!\\$&\\'\\(\\)\\*\\+,;=]";
91103

92-
private static final Pattern URI_CHARS_ANYMATCH =
93-
Pattern.compile(URI_CHARS_PAT);
94-
95104
private static final Pattern URI_CHARS_STARTSMATCH =
96105
Pattern.compile("^" + URI_CHARS_PAT);
97106

107+
/** Private to enforce singleton */
98108
private StringUtils() {
99-
// Only static utility methods
100109
}
101110

102111
/**
@@ -195,39 +204,19 @@ public static int nthIndexOf(String str, String substr, int n) {
195204
return pos;
196205
}
197206

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-
208207
/**
209208
* Determines if the {@code value} starts with characters matching
210-
* Common.lexh's {FNameChar}.
209+
* CommonPath.lexh's {FNameChar}.
211210
* @param value the input to test
212211
* @return true if {@code value} matches at its start
213212
*/
214213
public static boolean startsWithFnameChars(String value) {
215214
return FNAME_CHARS_STARTSMATCH.matcher(value).matches();
216215
}
217216

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-
228217
/**
229218
* 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.
231220
* @param value the input to test
232221
* @return true if {@code value} matches at its start
233222
*/
@@ -288,4 +277,14 @@ public static int patindexOf(String value, Pattern pattern) {
288277
if (!m.find()) return -1;
289278
return m.start();
290279
}
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+
}
291290
}

0 commit comments

Comments
 (0)