// Path: src/main/java/regexodus/REFlags.java
// public interface REFlags {
//     /**
//      * All the following options turned off, EXCEPT UNICODE. Unicode handling can be turned off with "-u" at the end
//      * of a flag string, or by simply specifying only the flags you want in a bitmask, like
//      * {@code (REFlags.IGNORE_CASE | REFlags.MULTILINE | REFlags.DOTALL)}.
//      * <br>
//      * This behavior changed between the 0.1.1 and 0.1.2 release.
//      */
//     int DEFAULT = 16;
// 
//     /**
//      * Pattern "a" matches both "a" and "A".
//      * Corresponds to "i" in Perl notation.
//      */
//     int IGNORE_CASE = 1 << 0;
// 
//     /**
//      * Affects the behaviour of "^" and "$" tags. When switched off:
//      * <ul>
//      * <li> the "^" matches the beginning of the whole text;</li>
//      * <li> the "$" matches the end of the whole text, or just before the '\n' or "\r\n" at the end of text.</li>
//      * </ul>
//      * When switched on:
//      * <ul>
//      * <li> the "^" additionally matches the line beginnings (that is just after the '\n');</li>
//      * <li> the "$" additionally matches the line ends (that is just before "\r\n" or '\n');</li>
//      * </ul>
//      * Corresponds to "m" in Perl notation.
//      */
//     int MULTILINE = 1 << 1;
// 
//     /**
//      * Affects the behaviour of dot(".") tag. When switched off:
//      * <ul>
//      * <li> the dot matches any character but EOLs('\r','\n');</li>
//      * </ul>
//      * When switched on:
//      * <ul>
//      * <li> the dot matches any character, including EOLs.</li>
//      * </ul>
//      * This flag is sometimes referenced in regex tutorials as SINGLELINE, which confusingly seems opposite to MULTILINE, but in fact is orthogonal.
//      * Corresponds to "s" in Perl notation.
//      */
//     int DOTALL = 1 << 2;
// 
//     /**
//      * Affects how the space characters are interpreted in the expression. When switched off:
//      * <ul>
//      * <li> the spaces are interpreted literally;</li>
//      * </ul>
//      * When switched on:
//      * <ul>
//      * <li> the spaces are ignored, allowing an expression to be slightly more readable.</li>
//      * </ul>
//      * Corresponds to "x" in Perl notation.
//      */
//     int IGNORE_SPACES = 1 << 3;
// 
//     /**
//      * Affects whether the predefined classes("\d","\s","\w",etc) in the expression are interpreted as belonging to Unicode. When switched off:
//      * <ul>
//      * <li> the predefined classes are interpreted as ASCII;</li>
//      * </ul>
//      * When switched on:
//      * <ul>
//      * <li> the predefined classes are interpreted as Unicode categories;</li>
//      * </ul>
//      * Defaults to switched on, unlike the others. When specifying a flags with an int, however, UNICODE doesn't get
//      * added automatically, so if you add a flag and want UNICODE on as well, you should specify it, too.
//      * <br>
//      * Corresponds to "u" in Perl notation.
//      */
//     int UNICODE = 1 << 4;
// 
//     /**
//      * Turns on the compatibility with XML Schema regular expressions.
//      * <br>
//      * Corresponds to "X" in Perl notation.
//      */
//     int XML_SCHEMA = 1 << 5;
// 
// 
// }


import regexodus.REFlags;
import java.io.Serializable;
import java.util.ArrayList;
     * <br>
     * This method produces a <code>String</code> that can be used to
     * create a <code>Pattern</code> that would match the string
     * <code>s</code> as if it were a literal pattern. Metacharacters
     * or escape sequences in the input sequence will be given no special
     * meaning.
     *
     * @param  s The string to be literalized
     * @return  A literal string replacement
     */
    public static String quote(String s) {
        int slashEIndex = s.indexOf("\\E");
        if (slashEIndex == -1)
            return "\\Q" + s + "\\E";

        StringBuilder sb = new StringBuilder(s.length() * 2);
        sb.append("\\Q");
        int current = 0;
        while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
            sb.append(s.substring(current, slashEIndex));
            current = slashEIndex + 2;
            sb.append("\\E\\\\E\\Q");
        }
        sb.append(s.substring(current, s.length()));
        sb.append("\\E");
        return sb.toString();
    }

    private Pattern(String p, int flags)
    {
// Path: src/main/java/regexodus/REFlags.java
// public interface REFlags {
//     /**
//      * All the following options turned off, EXCEPT UNICODE. Unicode handling can be turned off with "-u" at the end
//      * of a flag string, or by simply specifying only the flags you want in a bitmask, like
//      * {@code (REFlags.IGNORE_CASE | REFlags.MULTILINE | REFlags.DOTALL)}.
//      * <br>
//      * This behavior changed between the 0.1.1 and 0.1.2 release.
//      */
//     int DEFAULT = 16;
// 
//     /**
//      * Pattern "a" matches both "a" and "A".
//      * Corresponds to "i" in Perl notation.
//      */
//     int IGNORE_CASE = 1 << 0;
// 
//     /**
//      * Affects the behaviour of "^" and "$" tags. When switched off:
//      * <ul>
//      * <li> the "^" matches the beginning of the whole text;</li>
//      * <li> the "$" matches the end of the whole text, or just before the '\n' or "\r\n" at the end of text.</li>
//      * </ul>
//      * When switched on:
//      * <ul>
//      * <li> the "^" additionally matches the line beginnings (that is just after the '\n');</li>
//      * <li> the "$" additionally matches the line ends (that is just before "\r\n" or '\n');</li>
//      * </ul>
//      * Corresponds to "m" in Perl notation.
//      */
//     int MULTILINE = 1 << 1;
// 
//     /**
//      * Affects the behaviour of dot(".") tag. When switched off:
//      * <ul>
//      * <li> the dot matches any character but EOLs('\r','\n');</li>
//      * </ul>
//      * When switched on:
//      * <ul>
//      * <li> the dot matches any character, including EOLs.</li>
//      * </ul>
//      * This flag is sometimes referenced in regex tutorials as SINGLELINE, which confusingly seems opposite to MULTILINE, but in fact is orthogonal.
//      * Corresponds to "s" in Perl notation.
//      */
//     int DOTALL = 1 << 2;
// 
//     /**
//      * Affects how the space characters are interpreted in the expression. When switched off:
//      * <ul>
//      * <li> the spaces are interpreted literally;</li>
//      * </ul>
//      * When switched on:
//      * <ul>
//      * <li> the spaces are ignored, allowing an expression to be slightly more readable.</li>
//      * </ul>
//      * Corresponds to "x" in Perl notation.
//      */
//     int IGNORE_SPACES = 1 << 3;
// 
//     /**
//      * Affects whether the predefined classes("\d","\s","\w",etc) in the expression are interpreted as belonging to Unicode. When switched off:
//      * <ul>
//      * <li> the predefined classes are interpreted as ASCII;</li>
//      * </ul>
//      * When switched on:
//      * <ul>
//      * <li> the predefined classes are interpreted as Unicode categories;</li>
//      * </ul>
//      * Defaults to switched on, unlike the others. When specifying a flags with an int, however, UNICODE doesn't get
//      * added automatically, so if you add a flag and want UNICODE on as well, you should specify it, too.
//      * <br>
//      * Corresponds to "u" in Perl notation.
//      */
//     int UNICODE = 1 << 4;
// 
//     /**
//      * Turns on the compatibility with XML Schema regular expressions.
//      * <br>
//      * Corresponds to "X" in Perl notation.
//      */
//     int XML_SCHEMA = 1 << 5;
// 
// 
// }


// Path: src/main/java/regexodus/emu/java/util/regex/Pattern.java
import regexodus.REFlags;
import java.io.Serializable;
import java.util.ArrayList;

     * <br>
     * This method produces a <code>String</code> that can be used to
     * create a <code>Pattern</code> that would match the string
     * <code>s</code> as if it were a literal pattern. Metacharacters
     * or escape sequences in the input sequence will be given no special
     * meaning.
     *
     * @param  s The string to be literalized
     * @return  A literal string replacement
     */
    public static String quote(String s) {
        int slashEIndex = s.indexOf("\\E");
        if (slashEIndex == -1)
            return "\\Q" + s + "\\E";

        StringBuilder sb = new StringBuilder(s.length() * 2);
        sb.append("\\Q");
        int current = 0;
        while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
            sb.append(s.substring(current, slashEIndex));
            current = slashEIndex + 2;
            sb.append("\\E\\\\E\\Q");
        }
        sb.append(s.substring(current, s.length()));
        sb.append("\\E");
        return sb.toString();
    }

    private Pattern(String p, int flags)
    {
        int fm = (flags & CASE_INSENSITIVE) != 0 ? REFlags.IGNORE_CASE : 0;