in src/main/core-api/java/com/mysql/cj/util/StringUtils.java [884:988]
private static int wildCompareInternal(String searchIn, String searchFor) {
if (searchIn == null || searchFor == null) {
return WILD_COMPARE_NO_MATCH;
}
if (searchFor.equals("%")) {
return WILD_COMPARE_MATCH;
}
int searchForPos = 0;
int searchForEnd = searchFor.length();
int searchInPos = 0;
int searchInEnd = searchIn.length();
int result = WILD_COMPARE_NO_MATCH; /* Not found, using wildcards */
while (searchForPos != searchForEnd) {
while (searchFor.charAt(searchForPos) != WILDCARD_MANY && searchFor.charAt(searchForPos) != WILDCARD_ONE) {
if (searchFor.charAt(searchForPos) == WILDCARD_ESCAPE && searchForPos + 1 != searchForEnd) {
searchForPos++;
}
if (searchInPos == searchInEnd
|| Character.toUpperCase(searchFor.charAt(searchForPos++)) != Character.toUpperCase(searchIn.charAt(searchInPos++))) {
return WILD_COMPARE_CONTINUE_WITH_WILD; /* No match */
}
if (searchForPos == searchForEnd) {
return searchInPos != searchInEnd ? WILD_COMPARE_CONTINUE_WITH_WILD : WILD_COMPARE_MATCH; /* Match if both are at end */
}
result = WILD_COMPARE_CONTINUE_WITH_WILD; /* Found an anchor char */
}
if (searchFor.charAt(searchForPos) == WILDCARD_ONE) {
do {
if (searchInPos == searchInEnd) { /* Skip one char if possible */
return result;
}
searchInPos++;
} while (++searchForPos < searchForEnd && searchFor.charAt(searchForPos) == WILDCARD_ONE);
if (searchForPos == searchForEnd) {
break;
}
}
if (searchFor.charAt(searchForPos) == WILDCARD_MANY) { /* Found w_many */
searchForPos++;
/* Remove any '%' and '_' from the wild search string */
for (; searchForPos != searchForEnd; searchForPos++) {
if (searchFor.charAt(searchForPos) == WILDCARD_MANY) {
continue;
}
if (searchFor.charAt(searchForPos) == WILDCARD_ONE) {
if (searchInPos == searchInEnd) { /* Skip one char if possible */
return WILD_COMPARE_NO_MATCH;
}
searchInPos++;
continue;
}
break; /* Not a wild character */
}
if (searchForPos == searchForEnd) {
return WILD_COMPARE_MATCH; /* Ok if w_many is last */
}
if (searchInPos == searchInEnd) {
return WILD_COMPARE_NO_MATCH;
}
char cmp;
if ((cmp = searchFor.charAt(searchForPos)) == WILDCARD_ESCAPE && searchForPos + 1 != searchForEnd) {
cmp = searchFor.charAt(++searchForPos);
}
searchForPos++;
do {
while (searchInPos != searchInEnd && Character.toUpperCase(searchIn.charAt(searchInPos)) != Character.toUpperCase(cmp)) {
searchInPos++;
} /* Searches for an anchor char */
if (searchInPos++ == searchInEnd) {
return WILD_COMPARE_NO_MATCH;
}
int tmp = wildCompareInternal(searchIn.substring(searchInPos), searchFor.substring(searchForPos));
if (tmp <= 0) {
return tmp;
}
} while (searchInPos != searchInEnd);
return WILD_COMPARE_NO_MATCH;
}
}
return searchInPos != searchInEnd ? WILD_COMPARE_CONTINUE_WITH_WILD : WILD_COMPARE_MATCH;
}