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

📄 re.java

📁 jakarta-regexp-1.5 正则表达式的源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                                    }                                    break;                                case E_SPACE:                                case E_NSPACE:                                    if (!(Character.isWhitespace(c) == (opdata == E_SPACE)))                                    {                                        return -1;                                    }                                    break;                            }                            idx++;                            break;                        default:                            internalError("Unrecognized escape '" + opdata + "'");                    }                    break;                case OP_ANY:                    if ((matchFlags & MATCH_SINGLELINE) == MATCH_SINGLELINE) {                        // Match anything                        if (search.isEnd(idx))                        {                            return -1;                        }                    }                    else                    {                        // Match anything but a newline                        if (search.isEnd(idx) || isNewline(idx))                        {                            return -1;                        }                    }                    idx++;                    break;                case OP_ATOM:                    {                        // Match an atom value                        if (search.isEnd(idx))                        {                            return -1;                        }                        // Get length of atom and starting index                        // int lenAtom = opdata;                        int startAtom = node + nodeSize;                        // Give up if not enough input remains to have a match                        if (search.isEnd(opdata + idx - 1))                        {                            return -1;                        }                        // Match atom differently depending on casefolding flag                        final boolean caseFold =                            ((matchFlags & MATCH_CASEINDEPENDENT) != 0);                        for (int i = 0; i < opdata; i++)                        {                            if (compareChars(search.charAt(idx++), instruction[startAtom + i], caseFold) != 0)                            {                                return -1;                            }                        }                    }                    break;                case OP_POSIXCLASS:                    {                        // Out of input?                        if (search.isEnd(idx))                        {                            return -1;                        }                        switch (opdata)                        {                            case POSIX_CLASS_ALNUM:                                if (!Character.isLetterOrDigit(search.charAt(idx)))                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_ALPHA:                                if (!Character.isLetter(search.charAt(idx)))                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_DIGIT:                                if (!Character.isDigit(search.charAt(idx)))                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_BLANK: // JWL - bugbug: is this right??                                if (!Character.isSpaceChar(search.charAt(idx)))                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_SPACE:                                if (!Character.isWhitespace(search.charAt(idx)))                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_CNTRL:                                if (Character.getType(search.charAt(idx)) != Character.CONTROL)                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_GRAPH: // JWL - bugbug???                                switch (Character.getType(search.charAt(idx)))                                {                                    case Character.MATH_SYMBOL:                                    case Character.CURRENCY_SYMBOL:                                    case Character.MODIFIER_SYMBOL:                                    case Character.OTHER_SYMBOL:                                        break;                                    default:                                        return -1;                                }                                break;                            case POSIX_CLASS_LOWER:                                if (Character.getType(search.charAt(idx)) != Character.LOWERCASE_LETTER)                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_UPPER:                                if (Character.getType(search.charAt(idx)) != Character.UPPERCASE_LETTER)                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_PRINT:                                if (Character.getType(search.charAt(idx)) == Character.CONTROL)                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_PUNCT:                            {                                int type = Character.getType(search.charAt(idx));                                switch(type)                                {                                    case Character.DASH_PUNCTUATION:                                    case Character.START_PUNCTUATION:                                    case Character.END_PUNCTUATION:                                    case Character.CONNECTOR_PUNCTUATION:                                    case Character.OTHER_PUNCTUATION:                                        break;                                    default:                                        return -1;                                }                            }                            break;                            case POSIX_CLASS_XDIGIT: // JWL - bugbug??                            {                                boolean isXDigit = ((search.charAt(idx) >= '0' && search.charAt(idx) <= '9') ||                                                    (search.charAt(idx) >= 'a' && search.charAt(idx) <= 'f') ||                                                    (search.charAt(idx) >= 'A' && search.charAt(idx) <= 'F'));                                if (!isXDigit)                                {                                    return -1;                                }                            }                            break;                            case POSIX_CLASS_JSTART:                                if (!Character.isJavaIdentifierStart(search.charAt(idx)))                                {                                    return -1;                                }                                break;                            case POSIX_CLASS_JPART:                                if (!Character.isJavaIdentifierPart(search.charAt(idx)))                                {                                    return -1;                                }                                break;                            default:                                internalError("Bad posix class");                                break;                        }                        // Matched.                        idx++;                    }                    break;                case OP_ANYOF:                    {                        // Out of input?                        if (search.isEnd(idx))                        {                            return -1;                        }                        // Get character to match against character class and maybe casefold                        char c = search.charAt(idx);                        boolean caseFold = (matchFlags & MATCH_CASEINDEPENDENT) != 0;                        // Loop through character class checking our match character                        int idxRange = node + nodeSize;                        int idxEnd = idxRange + (opdata * 2);                        boolean match = false;                        for (int i = idxRange; !match && i < idxEnd; )                        {                            // Get start, end and match characters                            char s = instruction[i++];                            char e = instruction[i++];                            match = ((compareChars(c, s, caseFold) >= 0)                                     && (compareChars(c, e, caseFold) <= 0));                        }                        // Fail if we didn't match the character class                        if (!match)                        {                            return -1;                        }                        idx++;                    }                    break;                case OP_BRANCH:                {                    // Check for choices                    // FIXME Dead code - only reason to keep is backward compat with pre-compiled exprs. Remove?                    if (instruction[next /* + offsetOpcode */] != OP_BRANCH)                    {                        // If there aren't any other choices, just evaluate this branch.                        node += nodeSize;                        continue;                    }                    // Try all available branches                    int nextBranch;                    do                    {                        // Try matching the branch against the string                        if ((idxNew = matchNodes(node + nodeSize, maxNode, idx)) != -1)                        {                            return idxNew;                        }                        // Go to next branch (if any)                        nextBranch = (short) instruction[node + offsetNext];                        node += nextBranch;                    }                    while (nextBranch != 0 && (instruction[node /* + offsetOpcode */] == OP_BRANCH));                    // Failed to match any branch!                    return -1;                }                case OP_OPEN_CLUSTER:                case OP_CLOSE_CLUSTER:                    // starting or ending the matching of a subexpression which has no backref.                case OP_NOTHING:                case OP_GOTO:                    // Just advance to the next node without doing anything                    break;                case OP_CONTINUE:                    // Advance to the following node                    node += nodeSize;                    continue;                case OP_END:                    // Match has succeeded!                    setParenEnd(0, idx);                    return idx;                default:                    // Corrupt program                    internalError("Invalid opcode '" + opcode + "'");            }            // Advance to the next node in the program            node = next;        }        // We "should" never end up here        internalError("Corrupt program");        return -1;    }    /**     * Match the current regular expression program against the current     * input string, starting at index i of the input string.  This method     * is only meant for internal use.     *     * @param i The input string index to start matching at     * @return True if the input matched the expression     */    protected boolean matchAt(int i)    {        // Initialize start pointer, paren cache and paren count        start0 = -1;        end0   = -1;        start1 = -1;        end1   = -1;        start2 = -1;        end2   = -1;        startn = null;        endn   = null;        parenCount = 1;        setParenStart(0, i);        // Allocate backref arrays (unless optimizations indicate otherwise)        if ((program.flags & REProgram.OPT_HASBACKREFS) != 0)        {            startBackref = new int[maxParen];            endBackref = new int[maxParen];        }        // Match against string        int idx;        if ((idx = matchNodes(0, maxNode, i)) != -1)        {            setParenEnd(0, idx);            return true;        }

⌨️ 快捷键说明

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