public static string Escape(char c)
{
int code = (int)c;
if (code > 126)
return ToUnicodeRepr(code);
if (code < 32)
return string.Format("\\x{0:X}", code);
switch (c)
{
case '\0':
return @"\0";
case '\a':
return @"\a";
case '\b':
return @"\b";
case '\t':
return @"\t";
case '\r':
return @"\r";
case '\v':
return @"\v";
case '\f':
return @"\f";
case '\n':
return @"\n";
case '\u001B':
return @"\e";
case '\"':
return "\\\"";
case '\'':
return "\\\'";
case ' ':
return " ";
default:
if (code < 32)
return string.Format("\\x{0:X}", code);
else
return c.ToString();
}
}