⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 regularexpression.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                ret = Op.createCapture(-tok.getParenNumber(), next);            } else {                next = Op.createCapture(-tok.getParenNumber(), next);                next = compile(tok.getChild(0), next, reverse);                ret = Op.createCapture(tok.getParenNumber(), next);            }            break;        case Token.LOOKAHEAD:            ret = Op.createLook(Op.LOOKAHEAD, next, compile(tok.getChild(0), null, false));            break;        case Token.NEGATIVELOOKAHEAD:            ret = Op.createLook(Op.NEGATIVELOOKAHEAD, next, compile(tok.getChild(0), null, false));            break;        case Token.LOOKBEHIND:            ret = Op.createLook(Op.LOOKBEHIND, next, compile(tok.getChild(0), null, true));            break;        case Token.NEGATIVELOOKBEHIND:            ret = Op.createLook(Op.NEGATIVELOOKBEHIND, next, compile(tok.getChild(0), null, true));            break;        case Token.INDEPENDENT:            ret = Op.createIndependent(next, compile(tok.getChild(0), null, reverse));            break;        case Token.MODIFIERGROUP:            ret = Op.createModifier(next, compile(tok.getChild(0), null, reverse),                                    ((Token.ModifierToken)tok).getOptions(),                                    ((Token.ModifierToken)tok).getOptionsMask());            break;        case Token.CONDITION:            Token.ConditionToken ctok = (Token.ConditionToken)tok;            int ref = ctok.refNumber;            Op condition = ctok.condition == null ? null : compile(ctok.condition, null, reverse);            Op yes = compile(ctok.yes, next, reverse);            Op no = ctok.no == null ? null : compile(ctok.no, next, reverse);            ret = Op.createCondition(next, ref, condition, yes, no);            break;        default:            throw new RuntimeException("Unknown token type: "+tok.type);        } // switch (tok.type)        return ret;    }//Public    /**     * Checks whether the <var>target</var> text <strong>contains</strong> this pattern or not.     *     * @return true if the target is matched to this regular expression.     */    public boolean matches(char[]  target) {        return this.matches(target, 0,  target .length , (Match)null);    }    /**     * Checks whether the <var>target</var> text <strong>contains</strong> this pattern     * in specified range or not.     *     * @param start Start offset of the range.     * @param end  End offset +1 of the range.     * @return true if the target is matched to this regular expression.     */    public boolean matches(char[]  target, int start, int end) {        return this.matches(target, start, end, (Match)null);    }    /**     * Checks whether the <var>target</var> text <strong>contains</strong> this pattern or not.     *     * @param match A Match instance for storing matching result.     * @return Offset of the start position in <VAR>target</VAR>; or -1 if not match.     */    public boolean matches(char[]  target, Match match) {        return this.matches(target, 0,  target .length , match);    }    /**     * Checks whether the <var>target</var> text <strong>contains</strong> this pattern     * in specified range or not.     *     * @param start Start offset of the range.     * @param end  End offset +1 of the range.     * @param match A Match instance for storing matching result.     * @return Offset of the start position in <VAR>target</VAR>; or -1 if not match.     */    public boolean matches(char[]  target, int start, int end, Match match) {        synchronized (this) {            if (this.operations == null)                this.prepare();            if (this.context == null)                this.context = new Context();        }        Context con = null;        synchronized (this.context) {            con = this.context.inuse ? new Context() : this.context;            con.reset(target, start, end, this.numberOfClosures);        }        if (match != null) {            match.setNumberOfGroups(this.nofparen);            match.setSource(target);        } else if (this.hasBackReferences) {            match = new Match();            match.setNumberOfGroups(this.nofparen);            // Need not to call setSource() because            // a caller can not access this match instance.        }        con.match = match;        if (RegularExpression.isSet(this.options, XMLSCHEMA_MODE)) {            int matchEnd = this. matchCharArray (con, this.operations, con.start, 1, this.options);            //System.err.println("DEBUG: matchEnd="+matchEnd);            if (matchEnd == con.limit) {                if (con.match != null) {                    con.match.setBeginning(0, con.start);                    con.match.setEnd(0, matchEnd);                }                con.inuse = false;                return true;            }            return false;        }        /*         * The pattern has only fixed string.         * The engine uses Boyer-Moore.         */        if (this.fixedStringOnly) {            //System.err.println("DEBUG: fixed-only: "+this.fixedString);            int o = this.fixedStringTable.matches(target, con.start, con.limit);            if (o >= 0) {                if (con.match != null) {                    con.match.setBeginning(0, o);                    con.match.setEnd(0, o+this.fixedString.length());                }                con.inuse = false;                return true;            }            con.inuse = false;            return false;        }        /*         * The pattern contains a fixed string.         * The engine checks with Boyer-Moore whether the text contains the fixed string or not.         * If not, it return with false.         */        if (this.fixedString != null) {            int o = this.fixedStringTable.matches(target, con.start, con.limit);            if (o < 0) {                //System.err.println("Non-match in fixed-string search.");                con.inuse = false;                return false;            }        }        int limit = con.limit-this.minlength;        int matchStart;        int matchEnd = -1;        /*         * Checks whether the expression starts with ".*".         */        if (this.operations != null            && this.operations.type == Op.CLOSURE && this.operations.getChild().type == Op.DOT) {            if (isSet(this.options, SINGLE_LINE)) {                matchStart = con.start;                matchEnd = this. matchCharArray (con, this.operations, con.start, 1, this.options);            } else {                boolean previousIsEOL = true;                for (matchStart = con.start;  matchStart <= limit;  matchStart ++) {                    int ch =  target [  matchStart ] ;                    if (isEOLChar(ch)) {                        previousIsEOL = true;                    } else {                        if (previousIsEOL) {                            if (0 <= (matchEnd = this. matchCharArray (con, this.operations,                                                                       matchStart, 1, this.options)))                                break;                        }                        previousIsEOL = false;                    }                }            }        }        /*         * Optimization against the first character.         */        else if (this.firstChar != null) {            //System.err.println("DEBUG: with firstchar-matching: "+this.firstChar);            RangeToken range = this.firstChar;            if (RegularExpression.isSet(this.options, IGNORE_CASE)) {                range = this.firstChar.getCaseInsensitiveToken();                for (matchStart = con.start;  matchStart <= limit;  matchStart ++) {                    int ch =  target [  matchStart ] ;                    if (REUtil.isHighSurrogate(ch) && matchStart+1 < con.limit) {                        ch = REUtil.composeFromSurrogates(ch,  target [  matchStart+1 ] );                        if (!range.match(ch))  continue;                    } else {                        if (!range.match(ch)) {                            char ch1 = Character.toUpperCase((char)ch);                            if (!range.match(ch1))                                if (!range.match(Character.toLowerCase(ch1)))                                    continue;                        }                    }                    if (0 <= (matchEnd = this. matchCharArray (con, this.operations,                                                               matchStart, 1, this.options)))                        break;                }            } else {                for (matchStart = con.start;  matchStart <= limit;  matchStart ++) {                    int ch =  target [  matchStart ] ;                    if (REUtil.isHighSurrogate(ch) && matchStart+1 < con.limit)                        ch = REUtil.composeFromSurrogates(ch,  target [  matchStart+1 ] );                    if (!range.match(ch))  continue;                    if (0 <= (matchEnd = this. matchCharArray (con, this.operations,                                                               matchStart, 1, this.options)))                        break;                }            }        }        /*         * Straightforward matching.         */        else {            for (matchStart = con.start;  matchStart <= limit;  matchStart ++) {                if (0 <= (matchEnd = this. matchCharArray (con, this.operations, matchStart, 1, this.options)))                    break;            }        }        if (matchEnd >= 0) {            if (con.match != null) {                con.match.setBeginning(0, matchStart);                con.match.setEnd(0, matchEnd);            }            con.inuse = false;            return true;        } else {            con.inuse = false;            return false;        }    }/** * @return -1 when not match; offset of the end of matched string when match. */    private int matchCharArray (Context con, Op op, int offset, int dx, int opts) {        char[] target = con.charTarget;        while (true) {            if (op == null)                return isSet(opts, XMLSCHEMA_MODE) && offset != con.limit ? -1 : offset;            if (offset > con.limit || offset < con.start)                return -1;            switch (op.type) {            case Op.CHAR:                if (isSet(opts, IGNORE_CASE)) {                    int ch = op.getData();                    if (dx > 0) {                        if (offset >= con.limit || !matchIgnoreCase(ch,  target [  offset ] ))                            return -1;                        offset ++;                    } else {                        int o1 = offset-1;                        if (o1 >= con.limit || o1 < 0 || !matchIgnoreCase(ch,  target [  o1 ] ))                            return -1;                        offset = o1;                    }                } else {                    int ch = op.getData();                    if (dx > 0) {                        if (offset >= con.limit || ch !=  target [  offset ] )                            return -1;                        offset ++;                    } else {                        int o1 = offset-1;                        if (o1 >= con.limit || o1 < 0 || ch !=  target [  o1 ] )                            return -1;                        offset = o1;                    }                }                op = op.next;                break;            case Op.DOT:                if (dx > 0) {                    if (offset >= con.limit)                        return -1;                    int ch =  target [  offset ] ;                    if (isSet(opts, SINGLE_LINE)) {                        if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit)                            offset ++;                    } else {                        if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -