📄 regularexpression.java
字号:
if (0 > this. matchCharArray (con, op.getChild(), offset, -1, opts)) return -1; op = op.next; break; case Op.NEGATIVELOOKBEHIND: if (0 <= this. matchCharArray (con, op.getChild(), offset, -1, opts)) return -1; op = op.next; break; case Op.INDEPENDENT: { int ret = this. matchCharArray (con, op.getChild(), offset, dx, opts); if (ret < 0) return ret; offset = ret; op = op.next; } break; case Op.MODIFIER: { int localopts = opts; localopts |= op.getData(); localopts &= ~op.getData2(); //System.err.println("MODIFIER: "+Integer.toString(opts, 16)+" -> "+Integer.toString(localopts, 16)); int ret = this. matchCharArray (con, op.getChild(), offset, dx, localopts); if (ret < 0) return ret; offset = ret; op = op.next; } break; case Op.CONDITION: { Op.ConditionOp cop = (Op.ConditionOp)op; boolean matchp = false; if (cop.refNumber > 0) { if (cop.refNumber >= this.nofparen) throw new RuntimeException("Internal Error: Reference number must be more than zero: "+cop.refNumber); matchp = con.match.getBeginning(cop.refNumber) >= 0 && con.match.getEnd(cop.refNumber) >= 0; } else { matchp = 0 <= this. matchCharArray (con, cop.condition, offset, dx, opts); } if (matchp) { op = cop.yes; } else if (cop.no != null) { op = cop.no; } else { op = cop.next; } } break; default: throw new RuntimeException("Unknown operation type: "+op.type); } // switch (op.type) } // while } private static final int getPreviousWordType(char[] target, int begin, int end, int offset, int opts) { int ret = getWordType(target, begin, end, --offset, opts); while (ret == WT_IGNORE) ret = getWordType(target, begin, end, --offset, opts); return ret; } private static final int getWordType(char[] target, int begin, int end, int offset, int opts) { if (offset < begin || offset >= end) return WT_OTHER; return getWordType0( target [ offset ] , opts); } private static final boolean regionMatches(char[] target, int offset, int limit, String part, int partlen) { if (offset < 0) return false; if (limit-offset < partlen) return false; int i = 0; while (partlen-- > 0) { if ( target [ offset++ ] != part.charAt(i++)) return false; } return true; } private static final boolean regionMatches(char[] target, int offset, int limit, int offset2, int partlen) { if (offset < 0) return false; if (limit-offset < partlen) return false; int i = offset2; while (partlen-- > 0) { if ( target [ offset++ ] != target [ i++ ] ) return false; } return true; }/** * @see java.lang.String#regionMatches */ private static final boolean regionMatchesIgnoreCase(char[] target, int offset, int limit, String part, int partlen) { if (offset < 0) return false; if (limit-offset < partlen) return false; int i = 0; while (partlen-- > 0) { char ch1 = target [ offset++ ] ; char ch2 = part.charAt(i++); if (ch1 == ch2) continue; char uch1 = Character.toUpperCase(ch1); char uch2 = Character.toUpperCase(ch2); if (uch1 == uch2) continue; if (Character.toLowerCase(uch1) != Character.toLowerCase(uch2)) return false; } return true; } private static final boolean regionMatchesIgnoreCase(char[] target, int offset, int limit, int offset2, int partlen) { if (offset < 0) return false; if (limit-offset < partlen) return false; int i = offset2; while (partlen-- > 0) { char ch1 = target [ offset++ ] ; char ch2 = target [ i++ ] ; if (ch1 == ch2) continue; char uch1 = Character.toUpperCase(ch1); char uch2 = Character.toUpperCase(ch2); if (uch1 == uch2) continue; if (Character.toLowerCase(uch1) != Character.toLowerCase(uch2)) return false; } return true; } /** * 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(String 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(String 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(String 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(String 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)) { if (DEBUG) { System.err.println("target string="+target); } int matchEnd = this. matchString (con, this.operations, con.start, 1, this.options); if (DEBUG) { System.err.println("matchEnd="+matchEnd); System.err.println("con.limit="+con.limit); } 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. matchString (con, this.operations, con.start, 1, this.options); } else { boolean previousIsEOL = true; for (matchStart = con.start; matchStart <= limit; matchStart ++) { int ch = target .charAt( matchStart ) ; if (isEOLChar(ch)) { previousIsEOL = true; } else { if (previousIsEOL) { if (0 <= (matchEnd = this. matchString (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)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -