Пример #1
0
        public static string CreateStringImpl(char[] val)
        {
            if (val == null)
            {
                return(string.Empty);
            }
            if (val.Length == 0)
            {
                return(string.Empty);
            }

            InternalSystem.String result = InternalAllocateStr(val.Length);

            //"safe" implementation
            //for (int i = 0; i < val.Length; i++)
            //    result[i] = val[i];

            unsafe {
                char *ptrres = result._GetBuffer();

                for (int i = 0; i < val.Length; i++)
                {
                    *ptrres = val[i];
                    ptrres++;
                }
            }

            return(result as object as string);
        }
Пример #2
0
        public string Substring(int startIndex)
        {
            if (startIndex == 0)
            {
                return(this as object as string);
            }

            if (startIndex < 0 || startIndex > this.length)
            {
                throw new System.ArgumentOutOfRangeException("startIndex");
            }

            int newlen = this.length - startIndex;

            InternalSystem.String result = InternalAllocateStr(newlen);

            unsafe {
                char *ptrres = result._GetBuffer();
                char *ptr    = this._GetBuffer();

                ptr = ptr + startIndex;

                for (int i = 0; i < newlen; i++)
                {
                    *ptrres = *ptr;
                    ptrres++;
                    ptr++;
                }
            }

            return(result as object as string);
        }
Пример #3
0
        public static string Concat(InternalSystem.String[] strings)
        {
            int length = 0;

            foreach (String s in strings)
            {
                length = length + s.Length;
            }

            InternalSystem.String result = InternalAllocateStr(length);

            unsafe {
                char *ptrres = result._GetBuffer();

                foreach (String s in strings)
                {
                    char *ptr = s._GetBuffer();
                    for (int i = 0; i < s.length; i++)
                    {
                        *ptrres = *ptr;
                        ptrres++;
                        ptr++;
                    }
                }
            }
            return(result as object as string);
        }
Пример #4
0
 public static string Concat(InternalSystem.String a, InternalSystem.String b, InternalSystem.String c)
 {
     InternalSystem.String result = InternalAllocateStr(a.length + b.length + c.length);
     unsafe {
         char *ptrres = result._GetBuffer();
         char *ptr    = a._GetBuffer();
         for (int i = 0; i < a.length; i++)
         {
             *ptrres = *ptr;
             ptrres++;
             ptr++;
         }
         ptr = b._GetBuffer();
         for (int i = 0; i < b.length; i++)
         {
             *ptrres = *ptr;
             ptrres++;
             ptr++;
         }
         ptr = c._GetBuffer();
         for (int i = 0; i < c.length; i++)
         {
             *ptrres = *ptr;
             ptrres++;
             ptr++;
         }
     }
     return(result as object as string);
 }
Пример #5
0
        public string Substring(int startIndex, int length)
        {
            if (length < 0)
            {
                throw new System.ArgumentOutOfRangeException("length", "< 0");
            }
            if (startIndex < 0)
            {
                throw new System.ArgumentOutOfRangeException("startIndex", "< 0");
            }
            if (startIndex > this.length - length)
            {
                throw new System.ArgumentOutOfRangeException("startIndex + length > this.length");
            }

            if (length == 0)
            {
                return(String.Empty);
            }

            InternalSystem.String result = InternalAllocateStr(length);

            unsafe {
                char *ptrres = result._GetBuffer();
                char *ptr    = this._GetBuffer();

                ptr = ptr + startIndex;

                for (int i = 0; i < length; i++)
                {
                    *ptrres = *ptr;
                    ptrres++;
                    ptr++;
                }
            }

            return(result as object as string);
        }
Пример #6
0
        public static string CreateStringImpl(char[] val, int startIndex, int length)
        {
            if (val == null)
            {
                throw new System.ArgumentNullException("val");
            }
            if (startIndex < 0)
            {
                throw new System.ArgumentOutOfRangeException("startIndex");
            }
            if (length < 0)
            {
                throw new System.ArgumentOutOfRangeException("length");
            }
            if (startIndex > val.Length - length)
            {
                throw new System.ArgumentOutOfRangeException("Out of range");
            }
            if (length == 0)
            {
                return(string.Empty);
            }

            InternalSystem.String result = InternalAllocateStr(length);

            unsafe {
                char *ptrres = result._GetBuffer();

                for (int i = startIndex; i < length; i++)
                {
                    *ptrres = val[i];
                    ptrres++;
                }
            }

            return(result as object as string);
        }