Esempio n. 1
0
        public static bool IsSurrogate(char pChar)
        {
            // High surrogate
            if (UTF32String.IsHighSurrogate(pChar))
            {
                return(true);
            }

            // Low Surrogate
            if (UTF32String.IsLowSurrogate(pChar))
            {
                return(true);
            }

            // Not a surrogate
            return(false);
        }
Esempio n. 2
0
        public static int[] GetInts(char[] pChars, int pIndex, int pLength)
        {
            char c;
            char l;
            int  cIndex = 0;

            int[] buffer   = null;
            int[] intArray = null;

            // valid?
            if ((null == pChars) || (0 == pChars.Length))
            {
                return(new int[0]);
            }

            // validates
            if ((0 > pIndex) || (pIndex > pChars.Length))
            {
                pIndex = 0;
            }

            if ((0 > pLength) || (pLength > pChars.Length))
            {
                pLength = pChars.Length;
            }

            // create a temp buffer
            cIndex = 0;
            buffer = new int[pChars.Length];

            // for each char in the inputs.
            for (int index = pIndex; index < pLength; index++)
            {
                c = pChars[index];

                // if it starts with a low surrogate pairs
                // ignore it
                if (UTF32String.IsLowSurrogate(c))
                {
                    continue;
                }

                // check if it's a surrogate pair
                if (UTF32String.IsHighSurrogate(c))
                {
                    // end of the array?
                    if ((index + 1) < pLength)
                    {
                        l = pChars[++index];

                        // check if it's a low surrogate pair
                        if (UTF32String.IsLowSurrogate(l))
                        {
                            // convert it to the UTF32
                            buffer[cIndex++] = UTF32String.FromSurrogate(c, l);
                        }
                    }
                }
                else
                {
                    buffer[cIndex++] = (int)c;
                }
            }

            // create the internal buffer
            intArray = new int[cIndex];

            // Copy the data over
            Array.Copy(buffer, 0, intArray, 0, cIndex);

            return(intArray);
        }