Esempio n. 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);
        }
Esempio n. 2
0
        public static void RemoveNullTermination(ref NativeString A)
        {
            if (A[A.Length - 1].Equals('\0'))
            {
                A.ResizeUninitialized(A.Length - 1);
            }

            return;
        }
Esempio n. 3
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];
            }
        }
Esempio n. 4
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);
        }