public DescribedAs(string descriptionTemplate, Matcher matcher, object[] values) { DescribedAs describedAs = this; this.descriptionTemplate = descriptionTemplate; this.matcher = matcher; this.values = (object[]) values.Clone(); }
public Matcher matcher(CharSequence input) { if (!compiled) { lock(this) { if (!compiled) compile(); } } Matcher m = new Matcher(this, input); return m; }
internal boolean matchRef(Matcher matcher, int i, CharSequence seq) { int save = matcher.locals[localIndex]; matcher.locals[localIndex] = ~i; // HACK boolean ret = next.match(matcher, i, seq); matcher.locals[localIndex] = save; return ret; }
internal static void ReplaceMatch (string replacementPattern, Matcher match, StringBuffer sb, string input, PatternData patternData) { replacementPattern = JavaUtils.ReplaceAll (replacementPattern, COPY_ENTIRE_MATCH_PATTERN, match.group ()); replacementPattern = JavaUtils.ReplaceAll (replacementPattern, INPUT_BEFORE_MATCH_PATTERN, input.Substring (0, match.start ())); replacementPattern = JavaUtils.ReplaceAll (replacementPattern, INPUT_AFTER_MATCH_PATTERN, input.Substring (match.end ())); replacementPattern = JavaUtils.ReplaceAll (replacementPattern, INPUT_PATTERN, input); int groupsNumber = match.groupCount (); if (groupsNumber > 0) { Pattern p = Pattern.compile (LAST_CAPTURED_GROUP_PATTERN); Matcher m = p.matcher ((CharSequence) (object) replacementPattern); if (m.find ()) { while (groupsNumber > 0) { if (match.start (patternData.NetToJavaNumbersMap [groupsNumber]) >= 0) { break; } --groupsNumber; } if (groupsNumber > 0) { replacementPattern = m.replaceAll (match.group (patternData.NetToJavaNumbersMap [groupsNumber])); } } } match.appendReplacement (sb, replacementPattern); }
private string ReplaceGroupName (Matcher match, string reformattedPattern, PatternGrouping patternGrouping, RegexOptions options) { if (patternGrouping.GroupCount == -1){ return null; } string groupName = match.group (1); Pattern p = Pattern.compile (NUMBER); Matcher m = p.matcher ((CharSequence) (object) groupName); if (m.matches ()) { return ReplaceGroupNumber (match, reformattedPattern, patternGrouping, options); } if (!patternGrouping.GroupNameToNumberMap.Contains (groupName)) { return null; } int javaGroupNumber = patternGrouping.NetToJavaNumbersMap [(int) patternGrouping.GroupNameToNumberMap [groupName]]; return match.replaceFirst (@"\\" + javaGroupNumber); }
public static Matcher describedAs(string description, Matcher matcher, params object[] values) { return (Matcher) new DescribedAs(description, matcher, values); }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int[] src = buffer; int patternLength = src.Length; int last = matcher.to - patternLength; // Loop over all possible match positions in text while (i <= last) { // Loop over pattern from right to left for (int j = patternLength - 1; j >= 0; j--) { int ch = seq.charAt(i+j); if (ch != src[j]) { // Shift search to the right by the maximum of the // bad character shift and the good suffix shift i += Math.max(j + 1 - lastOcc[ch&0x7F], optoSft[j]); goto continue4; } } // Entire pattern matched starting at i matcher.first = i; boolean ret = next.match(matcher, i + patternLength, seq); if (ret) { matcher.first = i; matcher.groups[0] = matcher.first; matcher.groups[1] = matcher.last; return true; } i++; continue4: ; } // BnM is only used as the leading node in the unanchored case, // and it replaced its Start() which always searches to the end // if it doesn't find what it's looking for, so hitEnd is true. matcher._hitEnd = true; return false; }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { return (check(matcher, i, seq) & type) > 0 && next.match(matcher, i, seq); }
internal override boolean matchInit(Matcher matcher, int i, CharSequence seq) { int save = matcher.locals[countIndex]; boolean ret = false; if (0 < cmin) { matcher.locals[countIndex] = 1; ret = body.match(matcher, i, seq); } else if (next.match(matcher, i, seq)) { ret = true; } else if (0 < cmax) { matcher.locals[countIndex] = 1; ret = body.match(matcher, i, seq); } matcher.locals[countIndex] = save; return ret; }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { // Check for zero length group if (i > matcher.locals[beginIndex]) { int count = matcher.locals[countIndex]; if (count < cmin) { matcher.locals[countIndex] = count + 1; boolean result = body.match(matcher, i, seq); // If match failed we must backtrack, so // the loop count should NOT be incremented if (!result) matcher.locals[countIndex] = count; return result; } if (next.match(matcher, i, seq)) return true; if (count < cmax) { matcher.locals[countIndex] = count + 1; boolean result = body.match(matcher, i, seq); // If match failed we must backtrack, so // the loop count should NOT be incremented if (!result) matcher.locals[countIndex] = count; return result; } return false; } return next.match(matcher, i, seq); }
internal virtual boolean matchInit(Matcher matcher, int i, CharSequence seq) { int save = matcher.locals[countIndex]; boolean ret = false; if (0 < cmin) { matcher.locals[countIndex] = 1; ret = body.match(matcher, i, seq); } else if (0 < cmax) { matcher.locals[countIndex] = 1; ret = body.match(matcher, i, seq); if (ret == false) ret = next.match(matcher, i, seq); } else { ret = next.match(matcher, i, seq); } matcher.locals[countIndex] = save; return ret; }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { // Avoid infinite loop in zero-length case. if (i > matcher.locals[beginIndex]) { int count = matcher.locals[countIndex]; // This block is for before we reach the minimum // iterations required for the loop to match if (count < cmin) { matcher.locals[countIndex] = count + 1; boolean b = body.match(matcher, i, seq); // If match failed we must backtrack, so // the loop count should NOT be incremented if (!b) matcher.locals[countIndex] = count; // Return success or failure since we are under // minimum return b; } // This block is for after we have the minimum // iterations required for the loop to match if (count < cmax) { matcher.locals[countIndex] = count + 1; boolean b = body.match(matcher, i, seq); // If match failed we must backtrack, so // the loop count should NOT be incremented if (!b) matcher.locals[countIndex] = count; else return true; } } return next.match(matcher, i, seq); }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { return loop.matchInit(matcher, i, seq); }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int tmp = matcher.locals[localIndex]; if (tmp >= 0) { // This is the normal group case. // Save the group so we can unset it if it // backs off of a match. int groupStart = matcher.groups[groupIndex]; int groupEnd = matcher.groups[groupIndex+1]; matcher.groups[groupIndex] = tmp; matcher.groups[groupIndex+1] = i; if (next.match(matcher, i, seq)) { return true; } matcher.groups[groupIndex] = groupStart; matcher.groups[groupIndex+1] = groupEnd; return false; } else { // This is a group reference case. We don't need to save any // group info because it isn't really a group. matcher.last = i; return true; } }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { return head.matchRef(matcher, i, seq) && next.match(matcher, matcher.last, seq); }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int rmaxChars = countChars(seq, i, -rmax); int rminChars = countChars(seq, i, -rmin); int savedFrom = matcher.from; int savedLBT = matcher.lookbehindTo; boolean conditionMatched = false; int startIndex = (!matcher.transparentBounds) ? matcher.from : 0; int from = Math.max(i - rmaxChars, startIndex); matcher.lookbehindTo = i; // Relax transparent region boundaries for lookbehind if (matcher.transparentBounds) matcher.from = 0; for (int j = i - rminChars; !conditionMatched && j >= from; j -= j>from ? countChars(seq, j, -1) : 1) { conditionMatched = cond.match(matcher, j, seq); } //Reinstate region boundaries matcher.from = savedFrom; matcher.lookbehindTo = savedLBT; return !conditionMatched && next.match(matcher, i, seq); }
int check(Matcher matcher, int i, CharSequence seq) { int ch; boolean left = false; int startIndex = matcher.from; int endIndex = matcher.to; if (matcher.transparentBounds) { startIndex = 0; endIndex = matcher.getTextLength(); } if (i > startIndex) { ch = Character.codePointBefore(seq, i); left = (isWord(ch) || ((Character.getType(ch) == Character.NON_SPACING_MARK) && hasBaseCharacter(matcher, i-1, seq))); } boolean right = false; if (i < endIndex) { ch = Character.codePointAt(seq, i); right = (isWord(ch) || ((Character.getType(ch) == Character.NON_SPACING_MARK) && hasBaseCharacter(matcher, i, seq))); } else { // Tried to access char past the end matcher._hitEnd = true; // The addition of another char could wreck a boundary matcher._requireEnd = true; } return ((left ^ right) ? (right ? LEFT : RIGHT) : NONE); }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int j = matcher.groups[groupIndex]; int k = matcher.groups[groupIndex+1]; int groupSize = k - j; // If the referenced group didn't match, neither can this if (j < 0) return false; // If there isn't enough input left no match if (i + groupSize > matcher.to) { matcher._hitEnd = true; return false; } // Check each new char to make sure it matches what the group // referenced matched last time around for (int index=0; index<groupSize; index++) if (seq.charAt(i+index) != seq.charAt(j+index)) return false; return next.match(matcher, i+groupSize, seq); }
private static boolean hasBaseCharacter(Matcher matcher, int i, CharSequence seq) { int start = (!matcher.transparentBounds) ? matcher.from : 0; for (int x=i; x >= start; x--) { int ch = Character.codePointAt(seq, x); if (Character.isLetterOrDigit(ch)) return true; if (Character.getType(ch) == Character.NON_SPACING_MARK) continue; return false; } return false; }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int j = matcher.groups[groupIndex]; int k = matcher.groups[groupIndex+1]; int groupSize = k - j; // If the referenced group didn't match, neither can this if (j < 0) return false; // If there isn't enough input left no match if (i + groupSize > matcher.to) { matcher._hitEnd = true; return false; } // Check each new char to make sure it matches what the group // referenced matched last time around int x = i; for (int index=0; index<groupSize; index++) { int c1 = Character.codePointAt(seq, x); int c2 = Character.codePointAt(seq, j); if (c1 != c2) { if (doUnicodeCase) { int cc1 = Character.toUpperCase(c1); int cc2 = Character.toUpperCase(c2); if (cc1 != cc2 && Character.toLowerCase(cc1) != Character.toLowerCase(cc2)) return false; } else { if (ASCII.toLower(c1) != ASCII.toLower(c2)) return false; } } x += Character.charCount(c1); j += Character.charCount(c2); } return next.match(matcher, i+groupSize, seq); }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int[] src = buffer; int patternLength = src.Length; int last = matcher.to - lengthInChars; // Loop over all possible match positions in text while (i <= last) { // Loop over pattern from right to left int ch; for (int j = countChars(seq, i, patternLength), x = patternLength - 1; j > 0; j -= Character.charCount(ch), x--) { ch = Character.codePointBefore(seq, i+j); if (ch != src[x]) { // Shift search to the right by the maximum of the // bad character shift and the good suffix shift int n = Math.max(x + 1 - lastOcc[ch&0x7F], optoSft[x]); i += countChars(seq, i, n); goto continue5; } } // Entire pattern matched starting at i matcher.first = i; boolean ret = next.match(matcher, i + lengthInChars, seq); if (ret) { matcher.first = i; matcher.groups[0] = matcher.first; matcher.groups[1] = matcher.last; return true; } i += countChars(seq, i, 1); continue5: ; } matcher._hitEnd = true; return false; }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { if (atom is BnM) { return atom.match(matcher, i, seq) && next.match(matcher, matcher.last, seq); } for (;;) { if (i > matcher.to) { matcher._hitEnd = true; return false; } if (atom.match(matcher, i, seq)) { return next.match(matcher, matcher.last, seq); } i += countChars(seq, i, 1); matcher.first++; } }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { if (cond.match(matcher, i, seq)) { return yes.match(matcher, i, seq); } else { return not.match(matcher, i, seq); } }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int savedTo = matcher.to; boolean conditionMatched = false; // Relax transparent region boundaries for lookahead if (matcher.transparentBounds) matcher.to = matcher.getTextLength(); try { conditionMatched = cond.match(matcher, i, seq); } finally { // Reinstate region boundaries matcher.to = savedTo; } return conditionMatched && next.match(matcher, i, seq); }
private void AddGroup (Matcher m, GroupCollection groups, int javaGroupNumber, string text, Match match) { int netGroupNumber = _patternData.JavaToNetGroupNumbersMap [javaGroupNumber]; if (netGroupNumber == -1) { return; } int index = m.start (javaGroupNumber); if (index < 0){ if(groups[netGroupNumber] == null) groups.SetValue (new Group (), netGroupNumber); return; } Group group = new Group (text, index, m.end (javaGroupNumber) - index, match, netGroupNumber); groups.SetValue (group, netGroupNumber); }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int savedTo = matcher.to; boolean conditionMatched = false; // Relax transparent region boundaries for lookahead if (matcher.transparentBounds) matcher.to = matcher.getTextLength(); try { if (i < matcher.to) { conditionMatched = !cond.match(matcher, i, seq); } else { // If a negative lookahead succeeds then more input // could cause it to fail! matcher._requireEnd = true; conditionMatched = !cond.match(matcher, i, seq); } } finally { // Reinstate region boundaries matcher.to = savedTo; } return conditionMatched && next.match(matcher, i, seq); }
private string ReplaceGroupNumber (Matcher match, string reformattedPattern, PatternGrouping patternGrouping, RegexOptions options) { int groupNumber = int.Parse (match.group (1)); int javaGroupNumber = groupNumber; int groupCount = patternGrouping.GroupCount; if (groupCount == -1) { if ((options & RegexOptions.ExplicitCapture) == RegexOptions.ExplicitCapture) { groupCount = 0; } else { groupCount = JavaUtils.GroupCount (reformattedPattern); } } else { javaGroupNumber = patternGrouping.NetToJavaNumbersMap [groupNumber]; } if (groupNumber > groupCount) { return null; } return match.replaceFirst (@"\\" + javaGroupNumber); }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int savedFrom = matcher.from; boolean conditionMatched = false; int startIndex = (!matcher.transparentBounds) ? matcher.from : 0; int from = Math.max(i - rmax, startIndex); // Set end boundary int savedLBT = matcher.lookbehindTo; matcher.lookbehindTo = i; // Relax transparent region boundaries for lookbehind if (matcher.transparentBounds) matcher.from = 0; for (int j = i - rmin; !conditionMatched && j >= from; j--) { conditionMatched = cond.match(matcher, j, seq); } matcher.from = savedFrom; matcher.lookbehindTo = savedLBT; return conditionMatched && next.match(matcher, i, seq); }
public MatchResult toMatchResult() { Matcher result = new Matcher(this.parentPattern, text); result.first = this.first; result.last = this.last; result.groups = (int[])this.groups.Clone(); return result; }
internal override boolean match(Matcher matcher, int i, CharSequence seq) { int save = matcher.locals[localIndex]; matcher.locals[localIndex] = i; boolean ret = next.match(matcher, i, seq); matcher.locals[localIndex] = save; return ret; }