/
NikolayIvkin
/
sqlancer2
Обзор
Документация
Войти
/
NikolayIvkin
/
sqlancer2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/sqlancer/LikeImplementationHelper.java
57 строк
2 KB
Manuel Rigger
Enforce PMD UnnecessaryLocalBeforeReturn rule
29 май 2020, 00:02
29 май 2020, 00:02
dcc55c5
Код
Авторство
О чём код?
package sqlancer; public final class LikeImplementationHelper { private LikeImplementationHelper() { } public static boolean match(String str, String regex, int regexPosition, int strPosition, boolean caseSensitive) { if (strPosition == str.length() && regexPosition == regex.length()) { return true; } if (regexPosition >= regex.length()) { return false; } char cur = regex.charAt(regexPosition); if (strPosition >= str.length()) { if (cur == '%') { return match(str, regex, regexPosition + 1, strPosition, caseSensitive); } else { return false; } } switch (cur) { case '%': // match boolean foundMatch = match(str, regex, regexPosition, strPosition + 1, caseSensitive); if (!foundMatch) { return match(str, regex, regexPosition + 1, strPosition, caseSensitive); } else { return true; } case '_': return match(str, regex, regexPosition + 1, strPosition + 1, caseSensitive); default: boolean charMatches; if (!caseSensitive) { charMatches = toUpper(cur) == toUpper(str.charAt(strPosition)); } else { charMatches = cur == str.charAt(strPosition); } if (charMatches) { return match(str, regex, regexPosition + 1, strPosition + 1, caseSensitive); } else { return false; } } } private static char toUpper(char cur) { if (cur >= 'a' && cur <= 'z') { return (char) (cur + 'A' - 'a'); } else { return cur; } } }