/// <summary> /// Implements <see cref="Transliterator.HandleTransliterate(IReplaceable, TransliterationPosition, bool)"/>. /// </summary> protected override void HandleTransliterate(IReplaceable text, TransliterationPosition offsets, bool isIncremental) { // start and limit of the input range int start = offsets.Start; int limit = offsets.Limit; if (start >= limit) { return; } /* * Normalize as short chunks at a time as possible even in * bulk mode, so that styled text is minimally disrupted. * In incremental mode, a chunk that ends with offsets.limit * must not be normalized. * * If it was known that the input text is not styled, then * a bulk mode normalization could be used. * (For details, see the comment in the C++ version.) */ StringBuilder segment = new StringBuilder(); StringBuilder normalized = new StringBuilder(); int c = text.Char32At(start); do { int prev = start; // Skip at least one character so we make progress. // c holds the character at start. segment.Length = 0; do { segment.AppendCodePoint(c); start += Character.CharCount(c); } while (start < limit && !norm2.HasBoundaryBefore(c = text.Char32At(start))); if (start == limit && isIncremental && !norm2.HasBoundaryAfter(c)) { // stop in incremental mode when we reach the input limit // in case there are additional characters that could change the // normalization result start = prev; break; } norm2.Normalize(segment, normalized); if (!UTF16Plus.Equal(segment, normalized)) { // replace the input chunk with its normalized form text.Replace(prev, start - prev, normalized.ToString()); // ICU4N: Corrected 2nd parameter // update all necessary indexes accordingly int delta = normalized.Length - (start - prev); start += delta; limit += delta; } } while (start < limit); offsets.Start = start; offsets.ContextLimit += limit - offsets.Limit; offsets.Limit = limit; }
public virtual string Transform(string source) { return(norm2.Normalize(source)); }