public static bool Insert(ref NativeString A, int position, NativeString insertion) { EnforceNullTermination(ref A); RemoveNullTermination(ref insertion); bool success = true; if (position >= 0 && position < A.Length) { NativeString temp = new NativeString(A.Length - position, Allocator.Temp); temp.ResizeUninitialized(A.Length - position); for (int i = 0; i < temp.Length; i++) { temp[i] = A[position + i]; } OverWrite(ref A, position, insertion); OverWrite(ref A, position + insertion.Length, temp); EnforceNullTermination(ref A); } else { success = false; } return(success); }
public static int GetHashCode(NativeString A) { int[] charArray = A.ToArray(); string stringToHash = charArray.ToString(); int hash = stringToHash.GetHashCode(); return(hash); }
public static void RemoveNullTermination(ref NativeString A) { if (A[A.Length - 1].Equals('\0')) { A.ResizeUninitialized(A.Length - 1); } return; }
public static void EnforceNullTermination(ref NativeString A) { if (!A[A.Length - 1].Equals('\0')) { A.Add('\0'); } return; }
public static int ContainsAtORBefore(NativeString A, int position, NativeString subString) { int pos = -1; for (int i = 0; i < A.Length && i <= position && pos == -1; i++) { pos = ContainsAt(A, i, subString); } return(pos); }
public static int Contains(NativeString A, NativeString subString) { int pos = -1; for (int i = 0; i < A.Length && pos == -1; i++) { pos = ContainsAt(A, i, subString); } return(pos); }
public static void OverWrite(ref NativeString A, int position, NativeString stamp) { if ((position + stamp.Length) > A.Length) { A.ResizeUninitialized(position + stamp.Length); } for (int i = 0; i < stamp.Length; i++) { A[position + i] = stamp[i]; } }
private void Start() { NativeString t1 = (NativeString)"Hello"; t1.Add(' '); NativeString t2 = (NativeString)"World"; t1 = t1 + t2; t2.Dispose(); t1.Add('!'); Debug.Log(t1); t1.Dispose(); }
public static bool Replace(ref NativeString A, NativeString oldString, NativeString replacement) { EnforceNullTermination(ref A); RemoveNullTermination(ref oldString); RemoveNullTermination(ref replacement); int pos = Contains(A, oldString); if (pos != -1) { ReplaceAt(ref A, pos, oldString, replacement, false); } return(pos != -1); }
public static int ContainsAt(NativeString A, int position, NativeString subString) { int pos = -1; if (!((subString.Length + position) > A.Length)) { for (int j = 0; j < subString.Length && A[position + j].Equals(subString[j]); j++) { if (j == (subString.Length - 1)) { pos = position; } } } return(pos); }
public static bool ReplaceAt(ref NativeString A, int positon, NativeString oldString, NativeString replacement, bool checkForOldString = true) { EnforceNullTermination(ref A); RemoveNullTermination(ref oldString); RemoveNullTermination(ref replacement); int pos; if (checkForOldString == true) { pos = ContainsAt(A, positon, oldString); } else { pos = positon; } if (pos != -1) { NativeString temp = new NativeString(A.Length - (pos + oldString.Length), Allocator.Temp); temp.ResizeUninitialized(A.Length - (pos + oldString.Length)); int tempPos = pos + oldString.Length; for (int i = 0; i < temp.Length; i++) { temp[i] = A[tempPos]; tempPos++; } OverWrite(ref A, pos, replacement); OverWrite(ref A, pos + replacement.Length, temp); EnforceNullTermination(ref A); } return(pos != -1); }
public static bool Equals(NativeString A, NativeString B) { return(A == B); }
public NativeStringDebugView(NativeString array) { m_Array = array; }
/// <summary> /// This function takes a copy of native list A and appends/concatanates B to the end of it. /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <returns></returns> public NativeString Concatenate(NativeString A, NativeString B) { return(A + B); }
public static bool IsNullTerminated(NativeString A) { return(A[A.Length - 1] == '\0' ? true:false); }