Example #1
0
            private void GetRecursiveDecomposition(bool canonical, char ch, StringBuilder builder)
            {
                string decomp = UnicodeCharacterDataResolver.GetUnicodeDecompositionMapping(ch);

                if (decomp != null && !(canonical && UnicodeCharacterDataResolver.GetUnicodeDecompositionType(ch) != UnicodeDecompositionType.None))
                {
                    for (int i = 0; i < decomp.Length; ++i)
                    {
                        GetRecursiveDecomposition(canonical, decomp[i], builder);
                    }
                }
                else // if no decomp, append
                {
                    builder.Append(ch);
                }
            }
Example #2
0
            private void InternalCompose(StringBuilder target, ArrayList char_lengths)
            {
                if (target.Length == 0)
                {
                    return;
                }
                int  starterPos = 0;
                int  compPos    = 1;
                int  text_idx   = 0;
                char starterCh  = target[0];

                char_lengths[starterPos] = (int)char_lengths[starterPos] + 1;

                UnicodeCanonicalClass lastClass = UnicodeCharacterDataResolver.GetUnicodeCanonicalClass(starterCh);

                if (lastClass != UnicodeCanonicalClass.NR)
                {
                    lastClass = (UnicodeCanonicalClass)256; // fix for strings staring with a combining mark
                }
                int oldLen = target.Length;

                // Loop on the decomposed characters, combining where possible
                char ch;

                for (int decompPos = compPos; decompPos < target.Length; ++decompPos)
                {
                    ch = target[decompPos];
                    UnicodeCanonicalClass chClass = UnicodeCharacterDataResolver.GetUnicodeCanonicalClass(ch);
                    char composite = GetPairwiseComposition(starterCh, ch);
                    UnicodeDecompositionType composeType = UnicodeCharacterDataResolver.GetUnicodeDecompositionType(composite);

                    if (composeType == UnicodeDecompositionType.None &&
                        composite != BidiChars.NotAChar &&
                        (lastClass < chClass || lastClass == UnicodeCanonicalClass.NR))
                    {
                        target[starterPos]       = composite;
                        char_lengths[starterPos] = (int)char_lengths[starterPos] + 1;
                        // we know that we will only be replacing non-supplementaries by non-supplementaries
                        // so we don't have to adjust the decompPos
                        starterCh = composite;
                    }
                    else
                    {
                        if (chClass == UnicodeCanonicalClass.NR)
                        {
                            starterPos = compPos;
                            starterCh  = ch;
                            text_idx++;
                        }
                        lastClass       = chClass;
                        target[compPos] = ch;
                        //char_lengths[compPos] = (int)char_lengths[compPos] + 1;
                        int chkPos = compPos;
                        if ((int)char_lengths[chkPos] < 0)
                        {
                            while ((int)char_lengths[chkPos] < 0)
                            {
                                char_lengths[chkPos] = (int)char_lengths[chkPos] + 1;
                                char_lengths.Insert(compPos, 0);
                                chkPos++;
                            }
                        }
                        else
                        {
                            char_lengths[chkPos] = (int)char_lengths[chkPos] + 1;
                        }

                        if (target.Length != oldLen) // MAY HAVE TO ADJUST!
                        {
                            decompPos += target.Length - oldLen;
                            oldLen     = target.Length;
                        }
                        ++compPos;
                    }
                }
                target.Length = compPos;
                char_lengths.RemoveRange(compPos, char_lengths.Count - compPos);
            }