378 */
379 static Pattern toPattern(String mask) {
380 boolean disjunctionEmpty = true;
381 StringJoiner joiner = new StringJoiner("|");
382 for (String disjunct : mask.split("\\|")) {
383 if (disjunct.isEmpty())
384 continue;
385 disjunctionEmpty = false;
386 String regex = disjunctToRegex(disjunct.toLowerCase());
387 joiner.add(regex);
388 }
389 return disjunctionEmpty ? null : Pattern.compile(joiner.toString());
390 }
391
392 /**
393 * @param disjunct non-null mask disjunct
394 * @return java regex string corresponding to this mask
395 */
396 static String disjunctToRegex(String disjunct) {
397 String regex;
398 if (disjunct.startsWith("*")) {
399 regex = ".*" + quote(disjunct.substring(1));
400 } else if (disjunct.endsWith("*")) {
401 regex = quote(disjunct.substring(0, disjunct.length() - 1)) + ".*";
402 } else {
403 regex = quote(disjunct);
404 }
405 return regex;
406 }
407 }
|
378 */
379 static Pattern toPattern(String mask) {
380 boolean disjunctionEmpty = true;
381 StringJoiner joiner = new StringJoiner("|");
382 for (String disjunct : mask.split("\\|")) {
383 if (disjunct.isEmpty())
384 continue;
385 disjunctionEmpty = false;
386 String regex = disjunctToRegex(disjunct.toLowerCase());
387 joiner.add(regex);
388 }
389 return disjunctionEmpty ? null : Pattern.compile(joiner.toString());
390 }
391
392 /**
393 * @param disjunct non-null mask disjunct
394 * @return java regex string corresponding to this mask
395 */
396 static String disjunctToRegex(String disjunct) {
397 String regex;
398 if (disjunct.startsWith("*") && disjunct.endsWith("*")) {
399 regex = ".*" + quote(disjunct.substring(1, disjunct.length() - 1)) + ".*";
400 } else if (disjunct.startsWith("*")) {
401 regex = ".*" + quote(disjunct.substring(1));
402 } else if (disjunct.endsWith("*")) {
403 regex = quote(disjunct.substring(0, disjunct.length() - 1)) + ".*";
404 } else {
405 regex = quote(disjunct);
406 }
407 return regex;
408 }
409 }
|