src/main/java/com/basistech/tclre/Compiler.java
private void brackpart(State lp, State rp) throws RegexException {
        UnicodeSet set;
        /*
         * OK, well; if the user uses \U the item that comes next can be a full codepoint.
         * If the user does not, it might be part of a surrogate.
         */
        int c;
        // start and end chars of a range
        int startc;
        int endc = 0;
        int ele;

    /* parse something, get rid of special cases, take shortcuts */
        switch (nexttype) {
        case RANGE:         /* a-b-c or other botch */
            throw new RegexException("Invalid syntax in range expression.");
        case PLAIN:
            c = nextvalue;
            lex.next();
            if (c <= Character.MAX_VALUE && Character.isHighSurrogate((char)c)) {
                // some idiot could write a high surrogate and then immediate \\Uxxxxx, woof.
                char low = (char)nextvalue;
                lex.next();
                startc = Character.toCodePoint((char)c, low);
            } else {
                startc = c;
            }
        /* shortcut for ordinary char (not range, not MCCE leader) */
            if (!see(RANGE)) {
                onechr(startc, lp, rp);
                return;
            }
            break;
        // COLLEL and ECLASS are of dubious utility and don't try to get surrogates right.
        case COLLEL:
            String charName = scanplain();
            if (charName.length() == 0) {
                throw new RegexException("Missing character name for collation.");
            }
            ele = Locale.element(charName);
            if (ele == -1) {
                throw new RegexException("Invalid character name " + charName);
            } else {
                startc = (char)ele;
            }
            break;
        case ECLASS:
            charName = scanplain();
            if (charName.length() == 0) {
                throw new RegexException("Unterminated or invalid equivalence class.");
            }
            ele = Locale.element(charName);
            if (ele == -1) {
                throw new RegexException("Invalid character name " + charName);
            } else {
                startc = (char)ele;
            }
            set = Locale.eclass((char)startc, 0 != (cflags & Flags.REG_ICASE));
            dovec(set, lp, rp);
            return;
        case CCLASS:
            String className = scanplain();
            if (className.length() == 0) {
                throw new RegexException("Missing class name for char class.");
            }
            set = Locale.cclass(className, 0 != (cflags & Flags.REG_ICASE));
            dovec(set, lp, rp);
            return;

        default:
            throw new RegexException("Impossible lexical state.");
        }

        if (see(RANGE)) {
            lex.next();
            switch (nexttype) {
            case PLAIN:
            case RANGE:
                c = nextvalue;
                lex.next();
                if (c <= Character.MAX_VALUE && Character.isHighSurrogate((char)c)) {
                    char low = (char)nextvalue;
                    lex.next();
                    endc = Character.toCodePoint((char)c, low);
                } else {
                    endc = c;
                }
                break;
            case COLLEL:
                String charName = scanplain();
                if (charName.length() == 0) {
                    throw new RegexException("Missing character name in collation.");
                }

                // look up named character.
                ele = Locale.element(charName);
                if (ele == -1) {
                    throw new RegexException("Invalid character name " + charName);
                }
                break;
            default:
                throw new RegexException("Invalid syntax in range.");

            }
        } else {
            endc = startc;
        }

        set = new UnicodeSet(startc, endc);
        if (0 != (cflags & Flags.REG_ICASE)) {
            set.closeOver(UnicodeSet.ADD_CASE_MAPPINGS);
        }
        dovec(set, lp, rp);
    }
private void brackpart(State lp, State rp) throws RegexException {
        UnicodeSet set;
        /*
         * OK, well; if the user uses \U the item that comes next can be a full codepoint.
         * If the user does not, it might be part of a surrogate.
         */
        int c;
        // start and end chars of a range
        int startc;
        int endc = 0;
        int ele;

    /* parse something, get rid of special cases, take shortcuts */
        switch (nexttype) {
        case RANGE:         /* a-b-c or other botch */
            throw new RegexException("Invalid syntax in range expression.");
        case PLAIN:
            c = nextvalue;
            lex.next();
            if (c <= Character.MAX_VALUE && Character.isHighSurrogate((char)c)) {
                // some idiot could write a high surrogate and then immediate \\Uxxxxx, woof.
                char low = (char)nextvalue;
                lex.next();
                startc = Character.toCodePoint((char)c, low);
            } else {
                startc = c;
            }
        /* shortcut for ordinary char (not range, not MCCE leader) */
            if (!see(RANGE)) {
                onechr(startc, lp, rp);
                return;
            }
            break;
        // COLLEL and ECLASS are of dubious utility and don't try to get surrogates right.
        case COLLEL:
            String charName = scanplain();
            if (charName.length() == 0) {
                throw new RegexException("Missing character name for collation.");
            }
            ele = Locale.element(charName);
            if (ele == -1) {
                throw new RegexException("Invalid character name " + charName);
            } else {
                startc = (char)ele;
            }
            break;
        case ECLASS:
            charName = scanplain();
            if (charName.length() == 0) {
                throw new RegexException("Unterminated or invalid equivalence class.");
            }
            ele = Locale.element(charName);
            if (ele == -1) {
                throw new RegexException("Invalid character name " + charName);
            } else {
                startc = (char)ele;
            }
            set = Locale.eclass((char)startc, 0 != (cflags & Flags.REG_ICASE));
            dovec(set, lp, rp);
            return;
        case CCLASS:
            String className = scanplain();
            if (className.length() == 0) {
                throw new RegexException("Missing class name for char class.");
            }
            set = Locale.cclass(className, 0 != (cflags & Flags.REG_ICASE));
            dovec(set, lp, rp);
            return;

        default:
            throw new RegexException("Impossible lexical state.");
        }

        if (see(RANGE)) {
            lex.next();
            switch (nexttype) {
            case PLAIN:
            case RANGE:
                c = nextvalue;
                lex.next();
                if (c <= Character.MAX_VALUE && Character.isHighSurrogate((char)c)) {
                    char low = (char)nextvalue;
                    lex.next();
                    endc = Character.toCodePoint((char)c, low);
                } else {
                    endc = c;
                }
                break;
            case COLLEL:
                String charName = scanplain();
                if (charName.length() == 0) {
                    throw new RegexException("Missing character name in collation.");
                }

                // look up named character.
                ele = Locale.element(charName);
                if (ele == -1) {
                    throw new RegexException("Invalid character name " + charName);
                }
                break;
            default:
                throw new RegexException("Invalid syntax in range.");

            }
        } else {
            endc = startc;
        }

        set = new UnicodeSet(startc, endc);
        if (0 != (cflags & Flags.REG_ICASE)) {
            set.closeOver(UnicodeSet.ADD_CASE_MAPPINGS);
        }
        dovec(set, lp, rp);
    }
private void brackpart ( State lp , State rp ) throws RegexException { UnicodeSet set ; /*
         * OK, well; if the user uses \U the item that comes next can be a full codepoint.
         * If the user does not, it might be part of a surrogate.
         */ int c ; // start and end chars of a range int startc ; int endc = 0 ; int ele ; /* parse something, get rid of special cases, take shortcuts */ switch ( nexttype ) { case RANGE : /* a-b-c or other botch */ throw new RegexException ( "Invalid syntax in range expression." ) ; case PLAIN : c = nextvalue ; lex . next ( ) ; if ( c <= Character . MAX_VALUE && Character . isHighSurrogate ( ( char ) c ) ) { // some idiot could write a high surrogate and then immediate \\Uxxxxx, woof. char low = ( char ) nextvalue ; lex . next ( ) ; startc = Character . toCodePoint ( ( char ) c , low ) ; } else { startc = c ; } /* shortcut for ordinary char (not range, not MCCE leader) */ if ( ! see ( RANGE ) ) { onechr ( startc , lp , rp ) ; return ; } break ; // COLLEL and ECLASS are of dubious utility and don't try to get surrogates right. case COLLEL : String charName = scanplain ( ) ; if ( charName . length ( ) == 0 ) { throw new RegexException ( "Missing character name for collation." ) ; } ele = Locale . element ( charName ) ; if ( ele == - 1 ) { throw new RegexException ( "Invalid character name " + charName ) ; } else { startc = ( char ) ele ; } break ; case ECLASS : charName = scanplain ( ) ; if ( charName . length ( ) == 0 ) { throw new RegexException ( "Unterminated or invalid equivalence class." ) ; } ele = Locale . element ( charName ) ; if ( ele == - 1 ) { throw new RegexException ( "Invalid character name " + charName ) ; } else { startc = ( char ) ele ; } set = Locale . eclass ( ( char ) startc , 0 != ( cflags & Flags . REG_ICASE ) ) ; dovec ( set , lp , rp ) ; return ; case CCLASS : String className = scanplain ( ) ; if ( className . length ( ) == 0 ) { throw new RegexException ( "Missing class name for char class." ) ; } set = Locale . cclass ( className , 0 != ( cflags & Flags . REG_ICASE ) ) ; dovec ( set , lp , rp ) ; return ; default : throw new RegexException ( "Impossible lexical state." ) ; } if ( see ( RANGE ) ) { lex . next ( ) ; switch ( nexttype ) { case PLAIN : case RANGE : c = nextvalue ; lex . next ( ) ; if ( c <= Character . MAX_VALUE && Character . isHighSurrogate ( ( char ) c ) ) { char low = ( char ) nextvalue ; lex . next ( ) ; endc = Character . toCodePoint ( ( char ) c , low ) ; } else { endc = c ; } break ; case COLLEL : String charName = scanplain ( ) ; if ( charName . length ( ) == 0 ) { throw new RegexException ( "Missing character name in collation." ) ; } // look up named character. ele = Locale . element ( charName ) ; if ( ele == - 1 ) { throw new RegexException ( "Invalid character name " + charName ) ; } break ; default : throw new RegexException ( "Invalid syntax in range." ) ; } } else { endc = startc ; } set = new UnicodeSet ( startc , endc ) ; if ( 0 != ( cflags & Flags . REG_ICASE ) ) { set . closeOver ( UnicodeSet . ADD_CASE_MAPPINGS ) ; } dovec ( set , lp , rp ) ; }
brackpart - handle one item (or range) within a bracket expression
brackpart - handle one item ( or range ) within a bracket expression