public void WriteBase(SubStringStruct value)
 {
     if (value.Length != 0)
     {
         var length = value.Length << 1;
         PrepLengthBase(length);
         fixed (char* valueFixed = value.Value)
             MemoryUnsafe.Copy(valueFixed + value.StartIndex, Data + LengthBase, length);
         LengthBase += length;
     }
 }
 ///// <summary>
 ///// 模拟javascript解码函数unescape
 ///// </summary>
 ///// <param name="value">原字符串</param>
 ///// <returns>unescape解码后的字符串</returns>
 //public static unsafe string JavascriptUnescape(string value)
 //{
 //    if (value != null)
 //    {
 //        fixed (char* valueFixed = value)
 //        {
 //            char* start = valueFixed, end = valueFixed + value.Length;
 //            while (start != end && *start != '%')
 //            {
 //                if (*start == 0) *start = ' ';
 //                ++start;
 //            }
 //            if (start != end)
 //            {
 //                char* write = start;
 //                do
 //                {
 //                    if (*++start == 'u')
 //                    {
 //                        uint code = (uint)(*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
 //                        code <<= 4;
 //                        code += (uint)(*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
 //                        code <<= 4;
 //                        code += (uint)(*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
 //                        code <<= 4;
 //                        code += (uint)(*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
 //                        *write++ = code != 0 ? (char)code : ' ';
 //                    }
 //                    else
 //                    {
 //                        uint code = (uint)(*start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
 //                        code <<= 4;
 //                        code += (uint)(*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
 //                        *write++ = code != 0 ? (char)code : ' ';
 //                    }
 //                    while (++start < end && *start != '%') *write++ = *start != 0 ? *start : ' ';
 //                }
 //                while (start < end);
 //                return new string(valueFixed, 0, (int)(write - valueFixed));
 //            }
 //        }
 //    }
 //    return value;
 //}
 /// <summary>
 ///     模拟javascript解码函数unescape
 /// </summary>
 /// <param name="value">原字符串</param>
 /// <returns>unescape解码后的字符串</returns>
 internal static unsafe SubStringStruct JavascriptUnescape(SubStringStruct value)
 {
     if (value.Length != 0)
     {
         fixed (char* valueFixed = value.Value)
         {
             char* start = valueFixed + value.StartIndex, end = start + value.Length;
             while (start != end && *start != '%')
             {
                 if (*start == 0) *start = ' ';
                 ++start;
             }
             if (start != end)
             {
                 var write = start;
                 do
                 {
                     if (*++start == 'u')
                     {
                         var code =
                             (uint)
                                 (*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
                         code <<= 4;
                         code +=
                             (uint)
                                 (*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
                         code <<= 4;
                         code +=
                             (uint)
                                 (*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
                         code <<= 4;
                         code +=
                             (uint)
                                 (*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
                         *write++ = code != 0 ? (char) code : ' ';
                     }
                     else
                     {
                         var code =
                             (uint)
                                 (*start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
                         code <<= 4;
                         code +=
                             (uint)
                                 (*++start - '0' < 10 ? *start - '0' : ((*start & 0xdf) - ('0' + 'A' - '9' - 1)));
                         *write++ = code != 0 ? (char) code : ' ';
                     }
                     while (++start < end && *start != '%') *write++ = *start != 0 ? *start : ' ';
                 } while (start < end);
                 return SubStringStruct.Unsafe(value.Value, value.StartIndex,
                     (int) (write - valueFixed) - value.StartIndex);
             }
         }
     }
     return value;
 }
Esempio n. 3
0
 public static void ToString(SubStringStruct value, CharStreamPlus jsonStream)
 {
     if (value.Value == null) WriteNull(jsonStream);
     else
     {
         jsonStream.PrepLength(value.Length + 2);
         jsonStream.Unsafer.Write(Quote);
         jsonStream.WriteBase(value);
         jsonStream.Unsafer.Write(Quote);
     }
 }