Exemple #1
0
        public static ICollection <string> Expand(string start, string end, bool requireSameLength, ICollection <string> output)
        {
            if (start == null || end == null)
            {
                throw new ICUException("Range must have 2 valid strings");
            }
#pragma warning disable 612, 618
            int[] startCps = CharSequences.CodePoints(start);
            int[] endCps   = CharSequences.CodePoints(end);
#pragma warning restore 612, 618
            int startOffset = startCps.Length - endCps.Length;

            if (requireSameLength && startOffset != 0)
            {
                throw new ICUException("Range must have equal-length strings");
            }
            else if (startOffset < 0)
            {
                throw new ICUException("Range must have start-length ≥ end-length");
            }
            else if (endCps.Length == 0)
            {
                throw new ICUException("Range must have end-length > 0");
            }

            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < startOffset; ++i)
            {
                builder.AppendCodePoint(startCps[i]);
            }
            Add(0, startOffset, startCps, endCps, builder, output);
            return(output);
        }
Exemple #2
0
 public Ranges(string s)
 {
     int[] array = CharSequences.CodePoints(s);
     ranges = new Range[array.Length];
     for (int i = 0; i < array.Length; ++i)
     {
         ranges[i] = new Range(array[i], array[i]);
     }
 }
Exemple #3
0
            public Ranges(string s)
            {
#pragma warning disable 612, 618
                int[] array = CharSequences.CodePoints(s);
#pragma warning restore 612, 618
                ranges = new Range[array.Length];
                for (int i = 0; i < array.Length; ++i)
                {
                    ranges[i] = new Range(array[i], array[i]);
                }
            }
Exemple #4
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();
        }