public static String sieveToJavaRegex()

in core/src/main/java/org/apache/jsieve/comparators/ComparatorUtils.java [144:181]


    public static String sieveToJavaRegex(String pattern) {
        int ch;
        StringBuilder buffer = new StringBuilder(2 * pattern.length());
        boolean lastCharWasStar = false;
        for (ch = 0; ch < pattern.length(); ch++) {
            final char nextChar = pattern.charAt(ch);
            switch (nextChar) {
            case '*':
                //
                // Java Matcher has issues with repeated stars
                //
                if (!lastCharWasStar) {
                    buffer.append(".*");
                }
                break;
            case '?':
                buffer.append('.');
                break;
            case '\\':
                buffer.append('\\');
                if (ch == pattern.length() - 1)
                    buffer.append('\\');
                else if (isSieveMatcherSpecialChar(pattern.charAt(ch + 1)))
                    buffer.append(pattern.charAt(++ch));
                else
                    buffer.append('\\');
                break;
            default:
                if (isRegexSpecialChar(nextChar))
                    buffer.append('\\');
                buffer.append(nextChar);
                break;
            }
            // Workaround for issue with Java Matcher
            lastCharWasStar = '*' == nextChar;
        }
        return buffer.toString();
    }