/// <summary> /// Implements CharacterIterator.current() for String. /// </summary> /// /// <seealso cref="null"/> public char Current() { if (pos >= begin && pos < end) { return(text.CharAt(pos)); } else { return(ILOG.J2CsMapping.Text.CharacterIterator.Done); } }
/// <summary> /// Implements <see cref="M:IBM.ICU.Text.Transliterator.HandleTransliterate(IBM.ICU.Text.Replaceable, null, System.Boolean)"/>. /// </summary> /// protected internal override void HandleTransliterate(Replaceable text, Transliterator.Position pos, bool isIncremental) { int start = pos.start; int limit = pos.limit; int i, j, ipat; loop : { while (start < limit) { // Loop over the forms in spec[]. Exit this loop when we // match one of the specs. Exit the outer loop if a // partial match is detected and isIncremental is true. for (j = 0, ipat = 0; spec[ipat] != END; ++j) { // Read the header int prefixLen = spec[ipat++]; int suffixLen = spec[ipat++]; int radix = spec[ipat++]; int minDigits = spec[ipat++]; int maxDigits = spec[ipat++]; // s is a copy of start that is advanced over the // characters as we parse them. int s = start; bool match = true; for (i = 0; i < prefixLen; ++i) { if (s >= limit) { if (i > 0) { // We've already matched a character. This is // a partial match, so we return if in // incremental mode. In non-incremental mode, // go to the next spec. if (isIncremental) { goto gotoloop; } match = false; break; } } char c = text.CharAt(s++); if (c != spec[ipat + i]) { match = false; break; } } if (match) { int u = 0; int digitCount = 0; for (;;) { if (s >= limit) { // Check for partial match in incremental mode. if (s > start && isIncremental) { goto gotoloop; } break; } int ch = text.Char32At(s); int digit = IBM.ICU.Lang.UCharacter.Digit(ch, radix); if (digit < 0) { break; } s += IBM.ICU.Text.UTF16.GetCharCount(ch); u = (u * radix) + digit; if (++digitCount == maxDigits) { break; } } match = (digitCount >= minDigits); if (match) { for (i = 0; i < suffixLen; ++i) { if (s >= limit) { // Check for partial match in incremental mode. if (s > start && isIncremental) { goto gotoloop; } match = false; break; } char c_0 = text.CharAt(s++); if (c_0 != spec[ipat + prefixLen + i]) { match = false; break; } } if (match) { // At this point, we have a match String str = IBM.ICU.Text.UTF16.ValueOf(u); text.Replace(start, s, str); limit -= s - start - str.Length; // The following break statement leaves the // loop that is traversing the forms in // spec[]. We then parse the next input // character. break; } } } ipat += prefixLen + suffixLen; } if (start < limit) { start += IBM.ICU.Text.UTF16.GetCharCount(text.Char32At(start)); } } } gotoloop: ; pos.contextLimit += limit - pos.limit; pos.limit = limit; pos.start = start; }
/// <summary> /// Implements <see cref="M:IBM.ICU.Text.Transliterator.HandleTransliterate(IBM.ICU.Text.Replaceable, null, System.Boolean)"/>. /// </summary> /// protected internal override void HandleTransliterate(Replaceable text, Transliterator.Position pos, bool incremental) { int start = pos.start; int limit = pos.limit; StringBuilder buf = new StringBuilder(prefix); int prefixLen = prefix.Length; bool redoPrefix = false; while (start < limit) { int c = (grokSupplementals) ? (int)(text.Char32At(start)) : (int)(text.CharAt(start)); int charLen = (grokSupplementals) ? IBM.ICU.Text.UTF16.GetCharCount(c) : 1; if ((c & -65536) != 0 && supplementalHandler != null) { buf.Length = 0; buf.Append(supplementalHandler.prefix); IBM.ICU.Impl.Utility.AppendNumber(buf, c, supplementalHandler.radix, supplementalHandler.minDigits); buf.Append(supplementalHandler.suffix); redoPrefix = true; } else { if (redoPrefix) { buf.Length = 0; buf.Append(prefix); redoPrefix = false; } else { buf.Length = prefixLen; } IBM.ICU.Impl.Utility.AppendNumber(buf, c, radix, minDigits); buf.Append(suffix); } text.Replace(start, start + charLen, buf.ToString()); start += buf.Length; limit += buf.Length - charLen; } pos.contextLimit += limit - pos.limit; pos.limit = limit; pos.start = start; }
/// <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); }