/// <summary> /// 格式化ajax字符串 /// </summary> /// <param name="jsStream">js字符流</param> /// <param name="formatStream">格式化JSON字符流</param> private static unsafe void FormatQuote(CharStreamPlus jsStream, UnmanagedStreamPlus formatStream) { var length = jsStream.Length; char* start = jsStream.Char, end = start + length; formatStream.PrepLength(length <<= 1); for (var write = (char*) (formatStream.CurrentData); start != end; ++start) *write++ = *start == Quote ? '"' : *start; formatStream.Unsafer.AddLength(length); }
/// <summary> /// 格式化ajax字符串 /// </summary> /// <param name="jsStream">JS字符流</param> /// <param name="formatStream">格式化JSON字符流</param> internal static unsafe void FormatJavascript(CharStreamPlus jsStream, UnmanagedStreamPlus formatStream) { var length = FormatLength(jsStream); if (length == 0) { if (jsStream.Length != 0) FormatQuote(jsStream, formatStream); return; } length += jsStream.Length; formatStream.PrepLength(length <<= 1); for (char* start = jsStream.Char, write = (char*) (formatStream.CurrentData), end = start + jsStream.Length; start != end; ++start) { if (*start == Quote) *write++ = '"'; else if (*start == '\n') { *(int*) write = ('n' << 16) + '\\'; write += 2; } else if (*start == '\r') { *(int*) write = ('r' << 16) + '\\'; write += 2; } else { if (*start == '"' || *start == '\\') *write++ = '\\'; *write++ = *start; } } formatStream.Unsafer.AddLength(length); }