in repository/service/src/main/java/org/apache/karaf/cave/repository/service/bundlerepository/SimpleFilter.java [327:405]
public static List<String> parseSubstring(String value) {
List<String> pieces = new ArrayList<>();
int length = value.length();
boolean isSimple = true;
for (int idx = 0; idx < length; idx++) {
char c = value.charAt(idx);
if (c == '*' || c == '\\') {
isSimple = false;
break;
}
}
if (isSimple) {
pieces.add(value);
return pieces;
}
StringBuilder ss = new StringBuilder();
// int kind = SIMPLE; // assume until proven otherwise
boolean wasStar = false; // indicates last piece was a star
boolean leftstar = false; // track if the initial piece is a star
boolean rightstar = false; // track if the final piece is a star
int idx = 0;
// We assume (sub)strings can contain leading and trailing blanks
boolean escaped = false;
for (;;) {
if (idx >= length) {
if (wasStar) {
// insert last piece as "" to handle trailing star
rightstar = true;
} else {
pieces.add(ss.toString());
// accumulate the last piece
// note that in the case of
// (cn=); this might be
// the string "" (!=null)
}
ss.setLength(0);
break;
}
// Read the next character and account for escapes.
char c = value.charAt(idx++);
if (!escaped && (c == '*')) {
// If we have successive '*' characters, then we can
// effectively collapse them by ignoring succeeding ones.
if (!wasStar) {
if (ss.length() > 0) {
pieces.add(ss.toString()); // accumulate the pieces
// between '*' occurrences
}
ss.setLength(0);
// if this is a leading star, then track it
if (pieces.isEmpty()) {
leftstar = true;
}
wasStar = true;
}
} else if (!escaped && (c == '\\')) {
escaped = true;
} else {
escaped = false;
wasStar = false;
ss.append(c);
}
}
if (leftstar || rightstar || pieces.size() > 1) {
// insert leading and/or trailing "" to anchor ends
if (rightstar) {
pieces.add("");
}
if (leftstar) {
pieces.add(0, "");
}
}
return pieces;
}