private escapeSpecialChars ( String s ) : String | ||
s | String | |
return | String |
private String escapeSpecialChars(String s)
{
char c;
StringBuilder so = new StringBuilder();
int len = s.Length;
for (int i = 0; i < len; i++)
{
c = s[i];
/*
* note that some of these escape sequences are unique to Erlang,
* which is why the corresponding 'case' values use octal. The
* resulting string is, of course, in Erlang format.
*/
switch (c)
{
// some special escape sequences
case '\b':
so.Append("\\b");
break;
case (char)127:
so.Append("\\d");
break;
case (char)27:
so.Append("\\e");
break;
case '\f':
so.Append("\\f");
break;
case '\n':
so.Append("\\n");
break;
case '\r':
so.Append("\\r");
break;
case '\t':
so.Append("\\t");
break;
case (char)11:
so.Append("\\v");
break;
case '\\':
so.Append("\\\\");
break;
case '\'':
so.Append("\\'");
break;
case '\"':
so.Append("\\\"");
break;
default:
// some other character classes
if (c < 027)
{
// control chars show as "\^@", "\^A" etc
so.Append("\\^" + (char)('A' - 1 + c));
}
else if (c > 126)
{
// 8-bit chars show as \345 \344 \366 etc
so.Append("\\" + Convert.ToString(c, 8));
}
else
{
// character is printable without modification!
so.Append(c);
}
break;
}
}
return so.ToString();
}