Example #1
0
        private void expect(Transliterator t, String source, String expectedResult)
        {
            String result = t.Transliterate(source);

            expectAux(t.ID + ":String", source, result, expectedResult);

            ReplaceableString rsource = new ReplaceableString(source);

            t.Transliterate(rsource);
            result = rsource.ToString();
            expectAux(t.ID + ":Replaceable", source, result, expectedResult);

            // Test keyboard (incremental) transliteration -- this result
            // must be the same after we finalize (see below).
            rsource.Replace(0, rsource.Length, "");
            TransliterationPosition index = new TransliterationPosition();
            StringBuffer            log   = new StringBuffer();

            for (int i = 0; i < source.Length; ++i)
            {
                if (i != 0)
                {
                    log.Append(" + ");
                }
                log.Append(source[i]).Append(" -> ");
                t.Transliterate(rsource, index,
                                source[i] + "");
                // Append the string buffer with a vertical bar '|' where
                // the committed index is.
                String s = rsource.ToString();
                log.Append(s.Substring(0, index.Start)). // ICU4N: Checked 2nd parameter
                Append('|').
                Append(s.Substring(index.Start));
            }

            // As a final step in keyboard transliteration, we must call
            // transliterate to finish off any pending partial matches that
            // were waiting for more input.
            t.FinishTransliteration(rsource, index);
            result = rsource.ToString();
            log.Append(" => ").Append(rsource.ToString());
            expectAux(t.ID + ":Keyboard", log.ToString(),
                      result.Equals(expectedResult),
                      expectedResult);
        }