in repository/service/src/main/java/org/apache/karaf/cave/repository/service/bundlerepository/SimpleFilter.java [248:325]
private static SimpleFilter subfilter(String filter, int startIdx, int endIdx) {
final String opChars = "=<>~";
// Determine the ending index of the attribute name.
int attrEndIdx = startIdx;
for (int i = 0; i < (endIdx - startIdx); i++) {
char c = filter.charAt(startIdx + i);
if (opChars.indexOf(c) >= 0) {
break;
} else if (!Character.isWhitespace(c)) {
attrEndIdx = startIdx + i + 1;
}
}
if (attrEndIdx == startIdx) {
throw new IllegalArgumentException(
"Missing attribute name: " + filter.substring(startIdx, endIdx));
}
String attr = filter.substring(startIdx, attrEndIdx);
// Skip the attribute name and any following whitespace.
startIdx = skipWhitespace(filter, attrEndIdx);
// Determine the operator type.
int op;
switch (filter.charAt(startIdx)) {
case '=':
op = EQ;
startIdx++;
break;
case '<':
if (filter.charAt(startIdx + 1) != '=') {
throw new IllegalArgumentException(
"Unknown operator: " + filter.substring(startIdx, endIdx));
}
op = LTE;
startIdx += 2;
break;
case '>':
if (filter.charAt(startIdx + 1) != '=') {
throw new IllegalArgumentException(
"Unknown operator: " + filter.substring(startIdx, endIdx));
}
op = GTE;
startIdx += 2;
break;
case '~':
if (filter.charAt(startIdx + 1) != '=') {
throw new IllegalArgumentException(
"Unknown operator: " + filter.substring(startIdx, endIdx));
}
op = APPROX;
startIdx += 2;
break;
default:
throw new IllegalArgumentException(
"Unknown operator: " + filter.substring(startIdx, endIdx));
}
// Parse value.
Object value = toDecodedString(filter, startIdx, endIdx);
// Check if the equality comparison is actually a substring
// or present operation.
if (op == EQ) {
String valueStr = filter.substring(startIdx, endIdx);
List<String> values = parseSubstring(valueStr);
if ((values.size() == 2)
&& (values.get(0).length() == 0)
&& (values.get(1).length() == 0)) {
op = PRESENT;
} else if (values.size() > 1) {
op = SUBSTRING;
value = values;
}
}
return new SimpleFilter(attr, value, op);
}