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()); }
public UTF32String Insert(int pIndex, UTF32String pInsert) { if (null == pInsert) { return(this.Insert(pIndex, (int[])null)); } return(this.Insert(pIndex, pInsert.Ints)); }
public UTF32String(UTF32String pUTF32) { if (null != pUTF32) { m_internal = (int[])pUTF32.Ints.Clone(); } else { m_internal = new int[0]; } }
public static int[] GetInts(string pUTF16) { // valid? if (null == pUTF16) { return(new int[0]); } // return it return(UTF32String.GetInts(pUTF16.ToCharArray())); }
public bool EndsWith(UTF32String pPattern) { // valid if (null == pPattern) { return(false); } // Done return(this.EndsWith(pPattern.Ints)); }
public bool StartsWith(UTF32String pPattern) { // valid? if (null == pPattern) { return(false); } // Done. return(this.StartsWith(pPattern.Ints)); }
public static int[] GetInts(char[] pChars) { // valid? if (null == pChars) { return(new int[0]); } // return it return(UTF32String.GetInts(pChars, 0, pChars.Length)); }
public UTF32String Append(UTF32String pUTF32) { // valid? if (null == pUTF32) { return(new UTF32String(this.Ints)); } // create a new instance return(this.Append(pUTF32.Ints)); }
public static UTF32String FromUTF16(string pString) { char[] charArray = null; if (null != pString) { charArray = pString.ToCharArray(); } // create a new instance return(UTF32String.FromChars(charArray)); }
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); }
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)); }
//--------------------------------------------------------------------- // 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)); }
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); }
public UTF32String Append(char[] pChars) { return(this.Append(UTF32String.GetInts(pChars))); }
public UTF32String(char[] pInput) { m_internal = UTF32String.GetInts(pInput); }
public bool EndsWith(string pPattern) { return(this.EndsWith(UTF32String.GetInts(pPattern))); }
public bool StartsWith(string pPattern) { return(this.StartsWith(UTF32String.GetInts(pPattern))); }
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); }
public UTF32String(string pInput) { m_internal = UTF32String.GetInts(pInput); }