private string extractString(string text) {
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Literals#String Literals
StringBuilder sb = new StringBuilder(text);
int startIndex = 1; // Skip initial quote
int slashIndex = -1;
while ((slashIndex = sb.ToString().IndexOf(BS, startIndex)) != -1)
{
char escapeType = sb[slashIndex + 1];
switch (escapeType)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
string octalCode = String.Concat(sb[slashIndex+1], sb[slashIndex+2], sb[slashIndex+3]);
char octalChar = Latin1.GetChars(new byte[] { System.Convert.ToByte(octalCode, 8) } )[0];
sb.Remove(slashIndex, 4).Insert(slashIndex, octalChar);
break;
case 'x':
string asciiCode = String.Concat(sb[slashIndex+2], sb[slashIndex+3]);
char asciiChar = Latin1.GetChars(new byte[] { System.Convert.ToByte(asciiCode, 16) } )[0];
sb.Remove(slashIndex, 4).Insert(slashIndex, asciiChar);
break;
case 'u':
char unicodeChar = Convert.ToChar(Int32.Parse(sb[slashIndex + 2].ToString() + sb[slashIndex + 3] + sb[slashIndex+4] + sb[slashIndex+5], System.Globalization.NumberStyles.AllowHexSpecifier));
sb.Remove(slashIndex, 6).Insert(slashIndex, unicodeChar);
break;
case 'b': sb.Remove(slashIndex, 2).Insert(slashIndex, '\b'); break;
case 'f': sb.Remove(slashIndex, 2).Insert(slashIndex, '\f'); break;
case 'n': sb.Remove(slashIndex, 2).Insert(slashIndex, '\n'); break;
case 'r': sb.Remove(slashIndex, 2).Insert(slashIndex, '\r'); break;
case 't': sb.Remove(slashIndex, 2).Insert(slashIndex, '\t'); break;
case 'v': sb.Remove(slashIndex, 2).Insert(slashIndex, '\v'); break;
case '\'': sb.Remove(slashIndex, 2).Insert(slashIndex, '\''); break;
case '"': sb.Remove(slashIndex, 2).Insert(slashIndex, '"'); break;
case '\\': sb.Remove(slashIndex, 2).Insert(slashIndex, '\\'); break;
case '\r': if (sb[slashIndex+2] == '\n') sb.Remove(slashIndex, 3); else sb.Remove(slashIndex, 2); break;
default: sb.Remove(slashIndex, 2).Insert(slashIndex, escapeType); break;
}
startIndex = slashIndex + 1;
}
sb.Remove(0, 1);
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}