/// <summary> /// 数值转字符串 /// </summary> /// <param name="value">数值</param> /// <param name="charStream">字符流</param> internal static void ToString(long value, CharStreamPlus charStream) { char* chars = stackalloc char[22]; var index = ToString(value, chars); charStream.WriteBase(chars + index.Key, index.Value); }
/// <summary> /// 字节流转换成JSON字符串 /// </summary> /// <param name="jsonStream">JSON输出流,不能为null</param> /// <param name="start">起始位置,不能为null</param> /// <param name="end">结束位置,长度必须大于0</param> public static unsafe void ToJson(CharStreamPlus jsonStream, byte* start, byte* end) { jsonStream.WriteBase('['); for (AjaxPlus.ToString(*start, jsonStream); ++start != end; AjaxPlus.ToString(*start, jsonStream)) jsonStream.WriteBase(','); jsonStream.WriteBase(']'); }
/// <summary> /// 数值转字符串 /// </summary> /// <param name="value">数值</param> /// <param name="charStream">字符流</param> internal static void ToString(ulong value, CharStreamPlus charStream) { char* chars = stackalloc char[20]; KeyValueStruct<int, int> index = ToString(value, chars); charStream.WriteBase(chars + index.Key, index.Value); }
public static void ToString(string value, CharStreamPlus jsonStream) { jsonStream.PrepLength(value.Length + 2); jsonStream.Unsafer.Write(Quote); jsonStream.WriteBase(value); jsonStream.Unsafer.Write(Quote); }
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); } }
public static void ToString(bool value, CharStreamPlus jsonStream) { jsonStream.WriteBase(value ? '1' : '0'); }
public static unsafe void ToString(byte value, CharStreamPlus jsonStream) { if (value == 0) jsonStream.WriteBase('0'); else { jsonStream.PrepLength(4); var data = (byte*) jsonStream.CurrentChar; var nextValue = value >> 4; *(char*) data = '0'; *(char*) (data + sizeof (char)) = 'x'; *(char*) (data + sizeof (char)*2) = (char) (nextValue < 10 ? nextValue + '0' : (nextValue + ('0' + 'A' - '9' - 1))); *(char*) (data + sizeof (char)*3) = (char) ((value &= 15) < 10 ? value + '0' : (value + ('0' + 'A' - '9' - 1))); jsonStream.Unsafer.AddLength(4); } }
public static unsafe void ToString(sbyte value, CharStreamPlus jsonStream) { if (value == 0) jsonStream.WriteBase('0'); else { char* chars = stackalloc char[6]; if (value < 0) { if (value == -128) { jsonStream.PrepLength(4); var unsafeStream = jsonStream.Unsafer; unsafeStream.Write('-'); unsafeStream.Write('1'); unsafeStream.Write('2'); unsafeStream.Write('8'); } else { ToString((sbyte) -value, chars); jsonStream.WriteBase(chars + 1, 5); } } else { ToString(value, chars); jsonStream.WriteBase(chars + 2, 4); } } }
public static unsafe void ToString(ushort value, CharStreamPlus jsonStream) { char* chars = stackalloc char[8]; var index = ToString(value, chars); jsonStream.WriteBase(chars + index.Key, index.Value); }
public static unsafe void ToString(ulong value, CharStreamPlus jsonStream, bool isMaxToString = true) { if (value <= MaxValue || !isMaxToString) { char* chars = stackalloc char[20]; var index = ToString(value, chars); jsonStream.WriteBase(chars + index.Key, index.Value); } else { var unsafeStraem = jsonStream.Unsafer; jsonStream.PrepLength(22); unsafeStraem.Write(Quote); NumberPlus.ToString(value, jsonStream); unsafeStraem.Write(Quote); } }