📄 regularexpression.java
字号:
ch = REUtil.composeFromSurrogates(ch, target [ ++offset ] ); if (isEOLChar(ch)) return -1; } offset ++; } else { int o1 = offset-1; if (o1 >= con.limit || o1 < 0) return -1; int ch = target [ o1 ] ; if (isSet(opts, SINGLE_LINE)) { if (REUtil.isLowSurrogate(ch) && o1-1 >= 0) o1 --; } else { if (REUtil.isLowSurrogate(ch) && o1-1 >= 0) ch = REUtil.composeFromSurrogates( target [ --o1 ] , ch); if (!isEOLChar(ch)) return -1; } offset = o1; } op = op.next; break; case Op.RANGE: case Op.NRANGE: if (dx > 0) { if (offset >= con.limit) return -1; int ch = target [ offset ] ; if (REUtil.isHighSurrogate(ch) && offset+1 < con.limit) ch = REUtil.composeFromSurrogates(ch, target [ ++offset ] ); RangeToken tok = op.getToken(); if (isSet(opts, IGNORE_CASE)) { tok = tok.getCaseInsensitiveToken(); if (!tok.match(ch)) { if (ch >= 0x10000) return -1; char uch; if (!tok.match(uch = Character.toUpperCase((char)ch)) && !tok.match(Character.toLowerCase(uch))) return -1; } } else { if (!tok.match(ch)) return -1; } offset ++; } else { int o1 = offset-1; if (o1 >= con.limit || o1 < 0) return -1; int ch = target [ o1 ] ; if (REUtil.isLowSurrogate(ch) && o1-1 >= 0) ch = REUtil.composeFromSurrogates( target [ --o1 ] , ch); RangeToken tok = op.getToken(); if (isSet(opts, IGNORE_CASE)) { tok = tok.getCaseInsensitiveToken(); if (!tok.match(ch)) { if (ch >= 0x10000) return -1; char uch; if (!tok.match(uch = Character.toUpperCase((char)ch)) && !tok.match(Character.toLowerCase(uch))) return -1; } } else { if (!tok.match(ch)) return -1; } offset = o1; } op = op.next; break; case Op.ANCHOR: boolean go = false; switch (op.getData()) { case '^': if (isSet(opts, MULTIPLE_LINES)) { if (!(offset == con.start || offset > con.start && isEOLChar( target [ offset-1 ] ))) return -1; } else { if (offset != con.start) return -1; } break; case '@': // Internal use only. // The @ always matches line beginnings. if (!(offset == con.start || offset > con.start && isEOLChar( target [ offset-1 ] ))) return -1; break; case '$': if (isSet(opts, MULTIPLE_LINES)) { if (!(offset == con.limit || offset < con.limit && isEOLChar( target [ offset ] ))) return -1; } else { if (!(offset == con.limit || offset+1 == con.limit && isEOLChar( target [ offset ] ) || offset+2 == con.limit && target [ offset ] == CARRIAGE_RETURN && target [ offset+1 ] == LINE_FEED)) return -1; } break; case 'A': if (offset != con.start) return -1; break; case 'Z': if (!(offset == con.limit || offset+1 == con.limit && isEOLChar( target [ offset ] ) || offset+2 == con.limit && target [ offset ] == CARRIAGE_RETURN && target [ offset+1 ] == LINE_FEED)) return -1; break; case 'z': if (offset != con.limit) return -1; break; case 'b': if (con.length == 0) return -1; { int after = getWordType(target, con.start, con.limit, offset, opts); if (after == WT_IGNORE) return -1; int before = getPreviousWordType(target, con.start, con.limit, offset, opts); if (after == before) return -1; } break; case 'B': if (con.length == 0) go = true; else { int after = getWordType(target, con.start, con.limit, offset, opts); go = after == WT_IGNORE || after == getPreviousWordType(target, con.start, con.limit, offset, opts); } if (!go) return -1; break; case '<': if (con.length == 0 || offset == con.limit) return -1; if (getWordType(target, con.start, con.limit, offset, opts) != WT_LETTER || getPreviousWordType(target, con.start, con.limit, offset, opts) != WT_OTHER) return -1; break; case '>': if (con.length == 0 || offset == con.start) return -1; if (getWordType(target, con.start, con.limit, offset, opts) != WT_OTHER || getPreviousWordType(target, con.start, con.limit, offset, opts) != WT_LETTER) return -1; break; } // switch anchor type op = op.next; break; case Op.BACKREFERENCE: { int refno = op.getData(); if (refno <= 0 || refno >= this.nofparen) throw new RuntimeException("Internal Error: Reference number must be more than zero: "+refno); if (con.match.getBeginning(refno) < 0 || con.match.getEnd(refno) < 0) return -1; // ******** int o2 = con.match.getBeginning(refno); int literallen = con.match.getEnd(refno)-o2; if (!isSet(opts, IGNORE_CASE)) { if (dx > 0) { if (!regionMatches(target, offset, con.limit, o2, literallen)) return -1; offset += literallen; } else { if (!regionMatches(target, offset-literallen, con.limit, o2, literallen)) return -1; offset -= literallen; } } else { if (dx > 0) { if (!regionMatchesIgnoreCase(target, offset, con.limit, o2, literallen)) return -1; offset += literallen; } else { if (!regionMatchesIgnoreCase(target, offset-literallen, con.limit, o2, literallen)) return -1; offset -= literallen; } } } op = op.next; break; case Op.STRING: { String literal = op.getString(); int literallen = literal.length(); if (!isSet(opts, IGNORE_CASE)) { if (dx > 0) { if (!regionMatches(target, offset, con.limit, literal, literallen)) return -1; offset += literallen; } else { if (!regionMatches(target, offset-literallen, con.limit, literal, literallen)) return -1; offset -= literallen; } } else { if (dx > 0) { if (!regionMatchesIgnoreCase(target, offset, con.limit, literal, literallen)) return -1; offset += literallen; } else { if (!regionMatchesIgnoreCase(target, offset-literallen, con.limit, literal, literallen)) return -1; offset -= literallen; } } } op = op.next; break; case Op.CLOSURE: { /* * Saves current position to avoid * zero-width repeats. */ int id = op.getData(); if (id >= 0) { int previousOffset = con.offsets[id]; if (previousOffset < 0 || previousOffset != offset) { con.offsets[id] = offset; } else { con.offsets[id] = -1; op = op.next; break; } } int ret = this. matchCharArray (con, op.getChild(), offset, dx, opts); if (id >= 0) con.offsets[id] = -1; if (ret >= 0) return ret; op = op.next; } break; case Op.QUESTION: { int ret = this. matchCharArray (con, op.getChild(), offset, dx, opts); if (ret >= 0) return ret; op = op.next; } break; case Op.NONGREEDYCLOSURE: case Op.NONGREEDYQUESTION: { int ret = this. matchCharArray (con, op.next, offset, dx, opts); if (ret >= 0) return ret; op = op.getChild(); } break; case Op.UNION: for (int i = 0; i < op.size(); i ++) { int ret = this. matchCharArray (con, op.elementAt(i), offset, dx, opts); if (DEBUG) { System.err.println("UNION: "+i+", ret="+ret); } if (ret >= 0) return ret; } return -1; case Op.CAPTURE: int refno = op.getData(); if (con.match != null && refno > 0) { int save = con.match.getBeginning(refno); con.match.setBeginning(refno, offset); int ret = this. matchCharArray (con, op.next, offset, dx, opts); if (ret < 0) con.match.setBeginning(refno, save); return ret; } else if (con.match != null && refno < 0) { int index = -refno; int save = con.match.getEnd(index); con.match.setEnd(index, offset); int ret = this. matchCharArray (con, op.next, offset, dx, opts); if (ret < 0) con.match.setEnd(index, save); return ret; } op = op.next; break; case Op.LOOKAHEAD: if (0 > this. matchCharArray (con, op.getChild(), offset, 1, opts)) return -1; op = op.next; break; case Op.NEGATIVELOOKAHEAD: if (0 <= this. matchCharArray (con, op.getChild(), offset, 1, opts)) return -1; op = op.next; break; case Op.LOOKBEHIND:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -