示例#1
0
        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);
        }
示例#2
0
        public static int GetHashCode(NativeString A)
        {
            int[]  charArray    = A.ToArray();
            string stringToHash = charArray.ToString();
            int    hash         = stringToHash.GetHashCode();

            return(hash);
        }
示例#3
0
        public static void RemoveNullTermination(ref NativeString A)
        {
            if (A[A.Length - 1].Equals('\0'))
            {
                A.ResizeUninitialized(A.Length - 1);
            }

            return;
        }
示例#4
0
        public static void EnforceNullTermination(ref NativeString A)
        {
            if (!A[A.Length - 1].Equals('\0'))
            {
                A.Add('\0');
            }

            return;
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        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];
            }
        }
示例#8
0
        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();
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
 public static bool Equals(NativeString A, NativeString B)
 {
     return(A == B);
 }
示例#13
0
 public NativeStringDebugView(NativeString array)
 {
     m_Array = array;
 }
示例#14
0
 /// <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);
 }
示例#15
0
 public static bool IsNullTerminated(NativeString A)
 {
     return(A[A.Length - 1] == '\0' ? true:false);
 }