Ejemplo n.º 1
0
 /// <summary>
 /// System registration hook.
 /// </summary>
 internal static void Register()
 {
     Transliterator.RegisterFactory("Any-NFC", new Transliterator.Factory(getInstance: (id) =>
     {
         return(new NormalizationTransliterator("NFC", Normalizer2.GetNFCInstance()));
     }));
     Transliterator.RegisterFactory("Any-NFD", new Transliterator.Factory(getInstance: (id) =>
     {
         return(new NormalizationTransliterator("NFD", Normalizer2.GetNFDInstance()));
     }));
     Transliterator.RegisterFactory("Any-NFKC", new Transliterator.Factory(getInstance: (id) =>
     {
         return(new NormalizationTransliterator("NFKC", Normalizer2.GetNFKCInstance()));
     }));
     Transliterator.RegisterFactory("Any-NFKD", new Transliterator.Factory(getInstance: (id) =>
     {
         return(new NormalizationTransliterator("NFKD", Normalizer2.GetNFKDInstance()));
     }));
     Transliterator.RegisterFactory("Any-FCD", new Transliterator.Factory(getInstance: (id) =>
     {
         return(new NormalizationTransliterator("FCD", Norm2AllModes.GetFCDNormalizer2()));
     }));
     Transliterator.RegisterFactory("Any-FCC", new Transliterator.Factory(getInstance: (id) =>
     {
         return(new NormalizationTransliterator("FCC", Norm2AllModes.GetNFCInstance().Fcc));
     }));
     Transliterator.RegisterSpecialInverse("NFC", "NFD", true);
     Transliterator.RegisterSpecialInverse("NFKC", "NFKD", true);
     Transliterator.RegisterSpecialInverse("FCC", "NFD", false);
     Transliterator.RegisterSpecialInverse("FCD", "FCD", false);
 }
Ejemplo n.º 2
0
 /**
  * Constructs a transliterator.
  */
 private NormalizationTransliterator(string id, Normalizer2 n2)
     : base(id, null)
 {
     norm2 = n2;
 }
Ejemplo n.º 3
0
        public SourceTargetUtility(ITransform <string, string> transform, Normalizer2 normalizer)
        {
            this.transform = transform;
            if (normalizer != null)
            {
                //            synchronized (SourceTargetUtility.class) {
                //                if (NFC == null) {
                //                    NFC = Normalizer2.getInstance(null, "nfc", Mode.COMPOSE);
                //                    for (int i = 0; i <= 0x10FFFF; ++i) {
                //                        String d = NFC.getDecomposition(i);
                //                        if (d == null) {
                //                            continue;
                //                        }
                //                        String s = NFC.normalize(d);
                //                        if (!CharSequences.equals(i, s)) {
                //                            continue;
                //                        }
                //                        // composes
                //                        boolean first = false;
                //                        for (int trailing : CharSequences.codePoints(d)) {
                //                            if (first) {
                //                                first = false;
                //                            } else {
                //                                TRAILING_COMBINING.add(trailing);
                //                            }
                //                        }
                //                    }
                //                }
                //            }
                sourceCache = new UnicodeSet("[:^ccc=0:]");
            }
            else
            {
                sourceCache = new UnicodeSet();
            }
            sourceStrings = new HashSet <string>();
            for (int i = 0; i <= 0x10FFFF; ++i)
            {
                string s     = transform.Transform(UTF16.ValueOf(i));
                bool   added = false;
                if (!CharSequences.Equals(i, s))
                {
                    sourceCache.Add(i);
                    added = true;
                }
                if (normalizer == null)
                {
                    continue;
                }
                string d = NFC.GetDecomposition(i);
                if (d == null)
                {
                    continue;
                }
                s = transform.Transform(d);
                if (!d.Equals(s))
                {
                    sourceStrings.Add(d);
                }
                if (added)
                {
                    continue;
                }
                if (!normalizer.IsInert(i))
                {
                    sourceCache.Add(i);
                    continue;
                }
                // see if any of the non-starters change s; if so, add i
                //            for (String ns : TRAILING_COMBINING) {
                //                String s2 = transform.transform(s + ns);
                //                if (!s2.startsWith(s)) {
                //                    sourceCache.add(i);
                //                    break;
                //                }
                //            }

                // int endOfFirst = CharSequences.onCharacterBoundary(d, 1) ? 1 : 2;
                // if (endOfFirst >= d.length()) {
                // continue;
                // }
                // // now add all initial substrings
                // for (int j = 1; j < d.length(); ++j) {
                // if (!CharSequences.onCharacterBoundary(d, j)) {
                // continue;
                // }
                // String dd = d.substring(0,j);
                // s = transform.transform(dd);
                // if (!dd.equals(s)) {
                // sourceStrings.add(dd);
                // }
                // }
            }
            sourceCache.Freeze();
        }
Ejemplo n.º 4
0
 public NormalizingTransform(Normalizer2 norm2)
 {
     this.norm2 = norm2;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Constructs a filtered normalizer wrapping any <see cref="Normalizer2"/> instance
 /// and a filter set.
 /// Both are aliased and must not be modified or deleted while this object
 /// is used.
 /// The filter set should be frozen; otherwise the performance will suffer greatly.
 /// </summary>
 /// <param name="n2">Wrapped <see cref="Normalizer2"/> instance.</param>
 /// <param name="filterSet"><see cref="UnicodeSet"/> which determines the characters to be normalized.</param>
 /// <stable>ICU 4.4</stable>
 public FilteredNormalizer2(Normalizer2 n2, UnicodeSet filterSet)
 {
     norm2 = n2;
     set   = filterSet;
 }