public static int EscapedChar(string source, ref int index)
{
char chr = source[index++];
int valu;
switch (chr)
{
case '\\': return (int)'\\';
case 'a': return (int)'\a';
case 'b': return (int)'\b';
case 'f': return (int)'\f';
case 'n': return (int)'\n';
case 'r': return (int)'\r';
case 't': return (int)'\t';
case 'v': return (int)'\v';
case '0':
case '1':
case '2':
case '3':
if (chr == '0' && !IsOctDigit(source[index]))
return (int)'\0';
valu = GetOctalChar(GetSubstring(source, index - 1, 3)); index += 2;
if (valu >= 0)
return valu;
else
throw new StringInterpretException("Invalid escape", GetSubstring(source, index - 4, 4));
case 'x':
case 'X': // Just being nice here.
valu = GetHexadecimalChar(GetSubstring(source, index, 2)); index += 2;
if (valu >= 0)
return valu;
else
throw new StringInterpretException("Invalid escape", GetSubstring(source, index - 4, 4));
case 'u':
valu = GetUnicodeChar(GetSubstring(source, index, 4)); index += 4;
if (valu < 0)
throw new StringInterpretException("Invalid escape", GetSubstring(source, index - 6, 6));
else
return valu;
case 'U':
valu = GetUnicodeChar(GetSubstring(source, index, 8)); index += 8;
if (valu < 0)
throw new StringInterpretException("Invalid escape", GetSubstring(source, index - 10, 10));
else
return valu;
default:
return (int)chr;
}
}