Exemple #1
0
        // we have a segment, in NFD. Find all the strings that are canonically equivalent to it.
        private string[] GetEquivalents(string segment)
        {
            ISet <string> result       = new JCG.HashSet <string>();
            ISet <string> basic        = GetEquivalents2(segment);
            ISet <string> permutations = new JCG.HashSet <string>();

            // now get all the permutations
            // add only the ones that are canonically equivalent
            // TODO: optimize by not permuting any class zero.
            using (IEnumerator <string> it = basic.GetEnumerator())
            {
                while (it.MoveNext())
                {
                    string item = it.Current;
                    permutations.Clear();
#pragma warning disable 612, 618
                    Permute(item, SKIP_ZEROS, permutations);
#pragma warning restore 612, 618
                    using (IEnumerator <string> it2 = permutations.GetEnumerator())
                    {
                        while (it2.MoveNext())
                        {
                            string possible = it2.Current;

                            /*
                             *              String attempt = Normalizer.normalize(possible, Normalizer.DECOMP, 0);
                             *              if (attempt.equals(segment)) {
                             */
                            if (Normalizer.Compare(possible, segment, 0) == 0)
                            {
                                if (PROGRESS)
                                {
                                    Console.Out.WriteLine("Adding Permutation: " + Utility.Hex(possible));
                                }
                                result.Add(possible);
                            }
                            else
                            {
                                if (PROGRESS)
                                {
                                    Console.Out.WriteLine("-Skipping Permutation: " + Utility.Hex(possible));
                                }
                            }
                        }
                    }
                }
            }

            // convert into a String[] to clean up storage
            string[] finalResult = new string[result.Count];
            result.CopyTo(finalResult, 0);
            return(finalResult);
        }