コード例 #1
0
        /// <summary>
        /// Factory method.
        /// </summary>
        ///
        public static NormalizationTransliterator GetInstance(Normalizer.Mode m,
                                                              int opt)
        {
            StringBuilder id     = new StringBuilder("NF");
            int           choice = 0;

            if (m == IBM.ICU.Text.Normalizer.NFC)
            {
                id.Append("C");
                choice |= C;
            }
            else if (m == IBM.ICU.Text.Normalizer.NFKC)
            {
                id.Append("KC");
                choice |= KC;
            }
            else if (m == IBM.ICU.Text.Normalizer.NFD)
            {
                id.Append("D");
                choice |= D;
            }
            else if (m == IBM.ICU.Text.Normalizer.NFKD)
            {
                id.Append("KD");
                choice |= KD;
            }

            /*
             * if (m.compat()) { id.append('K'); choice |= KD; } if (m.compose()) {
             * id.append('C'); choice |= C; } else { id.append('D'); }
             */
            return(new NormalizationTransliterator(id.ToString(), m, choice, opt));
        }
コード例 #2
0
        /**
         * Do a normalization using the iterative API in the given direction.
         * @param str a Java StringCharacterIterator
         * @param buf scratch buffer
         * @param dir either +1 or -1
         */
        private String iterativeNorm(StringCharacterIterator str, Normalizer.Mode mode,
                                     StringBuffer buf, int dir, int options)
        {
            normalizer.SetText(str);
            normalizer.SetMode(mode);
            buf.Length = (0);
            normalizer.SetOption(-1, false);      // reset all options
            normalizer.SetOption(options, true);  // set desired options

            int ch;

            if (dir > 0)
            {
                for (ch = normalizer.First(); ch != Normalizer.DONE;
                     ch = normalizer.Next())
                {
                    buf.Append(UTF16.ValueOf(ch));
                }
            }
            else
            {
                for (ch = normalizer.Last(); ch != Normalizer.DONE;
                     ch = normalizer.Previous())
                {
                    buf.Insert(0, UTF16.ValueOf(ch));
                }
            }
            return(buf.ToString());
        }
コード例 #3
0
        private void cross(String s1, String s2, Normalizer.Mode mode)
        {
            String result = Normalizer.Normalize(s1, mode);

            if (!result.Equals(s2))
            {
                Errln("cross test failed s1: " + Utility.Hex(s1) + " s2: "
                      + Utility.Hex(s2));
            }
        }
コード例 #4
0
 /// <summary>
 /// Constructs a transliterator.
 /// </summary>
 ///
 private NormalizationTransliterator(String id, Normalizer.Mode m,
                                     int startChoice, int opt) : base(id, null)
 {
     this.buffer = new char[30];
     mode        = m;
     options     = opt;
     if (UNSAFE_STARTS[startChoice] == null)
     {
         InitStatics(startChoice);
     }
     // TODO: use built-in properties data rather than hardcoded sets; see
     // ICU4C
     unsafeStart = UNSAFE_STARTS[startChoice];
     skippable   = SKIPPABLES[startChoice];
 }
コード例 #5
0
 private static int getModeNumber(Normalizer.Mode mode)
 {
     if (mode == Normalizer.NFD)
     {
         return(0);
     }
     if (mode == Normalizer.NFKD)
     {
         return(1);
     }
     if (mode == Normalizer.NFC)
     {
         return(2);
     }
     if (mode == Normalizer.NFKC)
     {
         return(3);
     }
     return(-1);
 }
コード例 #6
0
        bool checkNorm(Normalizer.Mode mode, int options,  // Normalizer2 norm2,
                       String s, String exp, int field)
        {
            String       modeString = kModeStrings[getModeNumber(mode)];
            String       msg        = String.Format(kMessages[getModeNumber(mode)], field);
            StringBuffer buf        = new StringBuffer();
            String       @out       = Normalizer.Normalize(s, mode, options);

            if (!assertEqual(modeString, "", s, @out, exp, msg))
            {
                return(false);
            }

            @out = iterativeNorm(s, mode, buf, +1, options);
            if (!assertEqual(modeString, "(+1)", s, @out, exp, msg))
            {
                return(false);
            }

            @out = iterativeNorm(s, mode, buf, -1, options);
            if (!assertEqual(modeString, "(-1)", s, @out, exp, msg))
            {
                return(false);
            }

            @out = iterativeNorm(new StringCharacterIterator(s), mode, buf, +1, options);
            if (!assertEqual(modeString, "(+1)", s, @out, exp, msg))
            {
                return(false);
            }

            @out = iterativeNorm(new StringCharacterIterator(s), mode, buf, -1, options);
            if (!assertEqual(modeString, "(-1)", s, @out, exp, msg))
            {
                return(false);
            }

            return(true);
        }
コード例 #7
0
 /// <summary>
 /// Factory method.
 /// </summary>
 ///
 public static NormalizationTransliterator GetInstance(Normalizer.Mode m)
 {
     return(GetInstance(m, 0));
 }