コード例 #1
0
ファイル: EncodingCache.cs プロジェクト: AutoCSer/AutoCSer
 internal void WriteBytes(ref SubString value, UnmanagedStream stream)
 {
     if (value.Length != 0)
     {
         fixed(char *valueFixed = value.GetFixedBuffer()) WriteBytes(valueFixed + value.Start, value.Length, stream);
     }
 }
コード例 #2
0
 public void CallSerialize(SubString value)
 {
     if (value.Length == 0)
     {
         if (value.String != null)
         {
             emptyString();
         }
     }
     else
     {
         fixed(char *valueFixed = value.GetFixedBuffer()) serialize(valueFixed + value.Start, value.Length);
     }
 }
コード例 #3
0
        //        /// <summary>
        //        /// 字符替换
        //        /// </summary>
        //        /// <param name="value">原字符</param>
        //        /// <param name="replaceChar">替换后的字符</param>
        //        public void Replace(char value, char replaceChar)
        //        {
        //            if (Length != 0)
        //            {
        //                fixed (char* valueFixed = GetFixedBuffer())
        //                {
        //                    char* start = valueFixed + StartIndex, end = start + Length;
        //                    if (*--end == value)
        //                    {
        //                        do
        //                        {
        //                            while (*start != value) ++start;
        //                            *start = replaceChar;
        //                            if (start == end) return;
        //                            ++start;
        //                        }
        //                        while (true);
        //                    }
        //                    while (start != end)
        //                    {
        //                        if (*start == value) *start = replaceChar;
        //                        ++start;
        //                    }
        //                }
        //            }
        //        }
        /// <summary>
        /// 比较字符串大小
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        internal int CompareTo(ref SubString other)
        {
            int size = Math.Min(Length, other.Length);

            if (size == 0)
            {
                if (Length == 0)
                {
                    if (other.Length == 0)
                    {
                        if (String == null)
                        {
                            return(other.String == null ? 0 : -1);
                        }
                        return(other.String == null ? 1 : 0);
                    }
                    return(-1);
                }
                return(1);
            }

            fixed(char *stringFixed = GetFixedBuffer(), otherStringFixed = other.GetFixedBuffer())
            {
                char *start = stringFixed + Start, end = start + size, otherStart = otherStringFixed + other.Start;

                do
                {
                    if (*start != *otherStart)
                    {
                        return(*start - *otherStart);
                    }
                    ++otherStart;
                }while (++start != end);
            }

            return(Length - other.Length);
        }