コード例 #1
0
        /// <summary>
        /// Set a new source for this iterator. Allows object reuse.
        /// </summary>
        /// <param name="newSource">The source string to iterate against. This allows the same iterator to be used
        /// while changing the source string, saving object creation.</param>
        /// <stable>ICU 2.4</stable>
        public void SetSource(string newSource)
        {
            source = nfd.Normalize(newSource);
            done   = false;

            // catch degenerate case
            if (newSource.Length == 0)
            {
                pieces    = new string[1][];
                current   = new int[1];
                pieces[0] = new string[] { "" };
                return;
            }

            // find the segments
            IList <string> segmentList = new List <string>();
            int            cp;
            int            start = 0;

            // i should be the end of the first code point
            // break up the string into segements

            int i = UTF16.FindOffsetFromCodePoint(source, 1);

            for (; i < source.Length; i += Character.CharCount(cp))
            {
                cp = source.CodePointAt(i);
                if (nfcImpl.IsCanonSegmentStarter(cp))
                {
                    segmentList.Add(source.Substring(start, i - start)); // add up to i // ICU4N: Corrected 2nd substring parameter
                    start = i;
                }
            }
            segmentList.Add(source.Substring(start, i - start)); // add last one // ICU4N: Corrected 2nd substring parameter

            // allocate the arrays, and find the strings that are CE to each segment
            pieces  = new string[segmentList.Count][];
            current = new int[segmentList.Count];
            for (i = 0; i < pieces.Length; ++i)
            {
                if (PROGRESS)
                {
                    Console.Out.WriteLine("SEGMENT");
                }
                pieces[i] = GetEquivalents(segmentList[i]);
            }
        }