/// <summary> /// Implement UnicodeMatcher API. /// </summary> /// public virtual int Matches(Replaceable text, int[] offset, int limit, bool incremental) { int start = offset[0]; int count = 0; while (count < maxCount) { int pos = offset[0]; int m = matcher.Matches(text, offset, limit, incremental); if (m == IBM.ICU.Text.UnicodeMatcher_Constants.U_MATCH) { ++count; if (pos == offset[0]) { // If offset has not moved we have a zero-width match. // Don't keep matching it infinitely. break; } } else if (incremental && m == IBM.ICU.Text.UnicodeMatcher_Constants.U_PARTIAL_MATCH) { return(IBM.ICU.Text.UnicodeMatcher_Constants.U_PARTIAL_MATCH); } else { break; } } if (incremental && offset[0] == limit) { return(IBM.ICU.Text.UnicodeMatcher_Constants.U_PARTIAL_MATCH); } if (count >= minCount) { return(IBM.ICU.Text.UnicodeMatcher_Constants.U_MATCH); } offset[0] = start; return(IBM.ICU.Text.UnicodeMatcher_Constants.U_MISMATCH); }
/// <summary> /// Implement UnicodeMatcher /// </summary> /// public virtual int Matches(Replaceable text, int[] offset, int limit, bool incremental) { // Note (1): We process text in 16-bit code units, rather than // 32-bit code points. This works because stand-ins are // always in the BMP and because we are doing a literal match // operation, which can be done 16-bits at a time. int i; int[] cursor = new int[] { offset[0] }; if (limit < cursor[0]) { // Match in the reverse direction for (i = pattern.Length - 1; i >= 0; --i) { char keyChar = pattern[i]; // OK; see note (1) above UnicodeMatcher subm = data.LookupMatcher(keyChar); if (subm == null) { if (cursor[0] > limit && keyChar == text.CharAt(cursor[0])) // OK; // see // note // (1) // above { --cursor[0]; } else { return(IBM.ICU.Text.UnicodeMatcher_Constants.U_MISMATCH); } } else { int m = subm.Matches(text, cursor, limit, incremental); if (m != IBM.ICU.Text.UnicodeMatcher_Constants.U_MATCH) { return(m); } } } // Record the match position, but adjust for a normal // forward start, limit, and only if a prior match does not // exist -- we want the rightmost match. if (matchStart < 0) { matchStart = cursor[0] + 1; matchLimit = offset[0] + 1; } } else { for (i = 0; i < pattern.Length; ++i) { if (incremental && cursor[0] == limit) { // We've reached the context limit without a mismatch and // without completing our match. return(IBM.ICU.Text.UnicodeMatcher_Constants.U_PARTIAL_MATCH); } char keyChar_0 = pattern[i]; // OK; see note (1) above UnicodeMatcher subm_1 = data.LookupMatcher(keyChar_0); if (subm_1 == null) { // Don't need the cursor < limit check if // incremental is true (because it's done above); do need // it otherwise. if (cursor[0] < limit && keyChar_0 == text.CharAt(cursor[0])) // OK; // see // note // (1) // above { ++cursor[0]; } else { return(IBM.ICU.Text.UnicodeMatcher_Constants.U_MISMATCH); } } else { int m_2 = subm_1.Matches(text, cursor, limit, incremental); if (m_2 != IBM.ICU.Text.UnicodeMatcher_Constants.U_MATCH) { return(m_2); } } } // Record the match position matchStart = offset[0]; matchLimit = cursor[0]; } offset[0] = cursor[0]; return(IBM.ICU.Text.UnicodeMatcher_Constants.U_MATCH); }