namespace ZeroLevel.Services.Serialization
{
internal static class JsonEscaper
{
///
/// Checking if needed escaping string for use as json value
///
///
///
///
private static bool NeedEscape(string src, int i)
{
if (string.IsNullOrWhiteSpace(src)) return false;
char c = src[i];
return c < 32 || c == '"' || c == '\\'
// Broken lead surrogate
|| (c >= '\uD800' && c <= '\uDBFF' &&
(i == src.Length - 1 || src[i + 1] < '\uDC00' || src[i + 1] > '\uDFFF'))
// Broken tail surrogate
|| (c >= '\uDC00' && c <= '\uDFFF' &&
(i == 0 || src[i - 1] < '\uD800' || src[i - 1] > '\uDBFF'))
// To produce valid JavaScript
|| c == '\u2028' || c == '\u2029'
// Escape "" for