Ejemplo n.º 1
0
        public string ToUTF16()
        {
            int           cPoint     = 0;
            char          hSurrogate = (char)0;
            char          lSurrogate = (char)0;
            StringBuilder buffer     = null;

            // Initializes
            buffer = new StringBuilder();

            // for each char
            for (int index = 0; index < this.Length; index++)
            {
                cPoint = this[index];

                // need to split into surrogate?
                if ((cPoint & 0xf0000) != 0)
                {
                    hSurrogate = UTF32String.HighSurrogate(cPoint);
                    lSurrogate = UTF32String.LowSurrogate(cPoint);

                    // append surrogate
                    buffer.Append(hSurrogate);
                    buffer.Append(lSurrogate);
                }
                else
                {
                    buffer.Append((char)cPoint);
                }
            }

            // Done
            return(buffer.ToString());
        }
Ejemplo n.º 2
0
        public UTF32String Insert(int pIndex, UTF32String pInsert)
        {
            if (null == pInsert)
            {
                return(this.Insert(pIndex, (int[])null));
            }

            return(this.Insert(pIndex, pInsert.Ints));
        }
Ejemplo n.º 3
0
 public UTF32String(UTF32String pUTF32)
 {
     if (null != pUTF32)
     {
         m_internal = (int[])pUTF32.Ints.Clone();
     }
     else
     {
         m_internal = new int[0];
     }
 }
Ejemplo n.º 4
0
        public static int[] GetInts(string pUTF16)
        {
            // valid?
            if (null == pUTF16)
            {
                return(new int[0]);
            }

            // return it
            return(UTF32String.GetInts(pUTF16.ToCharArray()));
        }
Ejemplo n.º 5
0
        public bool EndsWith(UTF32String pPattern)
        {
            // valid
            if (null == pPattern)
            {
                return(false);
            }

            // Done
            return(this.EndsWith(pPattern.Ints));
        }
Ejemplo n.º 6
0
        public bool StartsWith(UTF32String pPattern)
        {
            // valid?
            if (null == pPattern)
            {
                return(false);
            }

            // Done.
            return(this.StartsWith(pPattern.Ints));
        }
Ejemplo n.º 7
0
        public static int[] GetInts(char[] pChars)
        {
            // valid?
            if (null == pChars)
            {
                return(new int[0]);
            }

            // return it
            return(UTF32String.GetInts(pChars, 0, pChars.Length));
        }
Ejemplo n.º 8
0
        public UTF32String Append(UTF32String pUTF32)
        {
            // valid?
            if (null == pUTF32)
            {
                return(new UTF32String(this.Ints));
            }

            // create a new instance
            return(this.Append(pUTF32.Ints));
        }
Ejemplo n.º 9
0
        public static UTF32String FromUTF16(string pString)
        {
            char[] charArray = null;

            if (null != pString)
            {
                charArray = pString.ToCharArray();
            }

            // create a new instance
            return(UTF32String.FromChars(charArray));
        }
Ejemplo n.º 10
0
        public UTF32String[] Split(int[] pSeperators)
        {
            int c = 0;

            int[]     eArray     = null;
            ArrayList entryArray = null;
            ArrayList entry      = null;

            UTF32String[] utfArray = null;

            entry      = new ArrayList();
            entryArray = new ArrayList();

            // for each char in the array
            for (int index = 0; index < this.Length; index++)
            {
                c = this[index];
                if (this.IsInArray(pSeperators, c))
                {
                    eArray = new int[entry.Count];
                    entry.CopyTo(0, eArray, 0, entry.Count);

                    // add the entry array
                    entryArray.Add(new UTF32String(eArray));

                    // clear it
                    entry.Clear();
                }
                else
                {
                    entry.Add(c);
                }
            }

            // left over?
            if (0 != entry.Count)
            {
                eArray = new int[entry.Count];
                entry.CopyTo(0, eArray, 0, entry.Count);

                // add the entry array
                entryArray.Add(new UTF32String(eArray));
            }

            utfArray = new UTF32String[entryArray.Count];

            // copy it to the array.
            entryArray.CopyTo(0, utfArray, 0, entryArray.Count);

            // Done
            return(utfArray);
        }
Ejemplo n.º 11
0
        public static UTF32String FromBytes(byte[] pBytes)
        {
            char[] charArray = null;

            // valid?
            if (null != pBytes)
            {
                charArray = UnicodeEncoding.UTF8.GetChars(pBytes);
            }

            // create a new instance
            return(UTF32String.FromChars(charArray));
        }
Ejemplo n.º 12
0
        //---------------------------------------------------------------------
        // Public Static Methods
        //---------------------------------------------------------------------
        public static UTF32String FromChars(char[] pChars)
        {
            int[] intArray = null;

            // valid?
            if (null != pChars)
            {
                intArray = UTF32String.GetInts(pChars);
            }

            // create a new instance
            return(new UTF32String(intArray));
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
0
 public UTF32String Append(char[] pChars)
 {
     return(this.Append(UTF32String.GetInts(pChars)));
 }
Ejemplo n.º 15
0
 public UTF32String(char[] pInput)
 {
     m_internal = UTF32String.GetInts(pInput);
 }
Ejemplo n.º 16
0
 public bool EndsWith(string pPattern)
 {
     return(this.EndsWith(UTF32String.GetInts(pPattern)));
 }
Ejemplo n.º 17
0
 public bool StartsWith(string pPattern)
 {
     return(this.StartsWith(UTF32String.GetInts(pPattern)));
 }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
 public UTF32String(string pInput)
 {
     m_internal = UTF32String.GetInts(pInput);
 }