protected static string ParseNumber(char[] json, ref int index, ref bool success) { JsonParser.EatWhitespace(json, ref index); int lastIndexOfNumber = JsonParser.GetLastIndexOfNumber(json, index); int length = lastIndexOfNumber - index + 1; string result = new string(json, index, length); success = true; index = lastIndexOfNumber + 1; return(result); }
protected static int NextToken(char[] json, ref int index) { JsonParser.EatWhitespace(json, ref index); if (index == json.Length) { return(0); } char c = json[index]; index++; char c2 = c; switch (c2) { case '"': return(7); case '#': case '$': case '%': case '&': case '\'': case '(': case ')': case '*': case '+': case '.': case '/': break; case ',': return(6); case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return(8); case ':': return(5); default: switch (c2) { case '[': return(3); case '\\': break; case ']': return(4); default: switch (c2) { case '{': return(1); case '}': return(2); } break; } break; } index--; int num = json.Length - index; if (num >= 5 && json[index] == 'f' && json[index + 1] == 'a' && json[index + 2] == 'l' && json[index + 3] == 's' && json[index + 4] == 'e') { index += 5; return(10); } if (num >= 4 && json[index] == 't' && json[index + 1] == 'r' && json[index + 2] == 'u' && json[index + 3] == 'e') { index += 4; return(9); } if (num >= 4 && json[index] == 'n' && json[index + 1] == 'u' && json[index + 2] == 'l' && json[index + 3] == 'l') { index += 4; return(11); } return(0); }
protected static int NextToken(char[] json, ref int index) { JsonParser.EatWhitespace(json, ref index); if (index == json.Length) { return(0); } char ch = json[index]; ++index; switch (ch) { case '"': return(7); case ',': return(6); case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return(8); case ':': return(5); case '[': return(3); case ']': return(4); case '{': return(1); case '}': return(2); default: --index; int num = json.Length - index; if (num >= 5 && (int)json[index] == 102 && ((int)json[index + 1] == 97 && (int)json[index + 2] == 108) && ((int)json[index + 3] == 115 && (int)json[index + 4] == 101)) { index += 5; return(10); } if (num >= 4 && (int)json[index] == 116 && ((int)json[index + 1] == 114 && (int)json[index + 2] == 117) && (int)json[index + 3] == 101) { index += 4; return(9); } if (num < 4 || (int)json[index] != 110 || ((int)json[index + 1] != 117 || (int)json[index + 2] != 108) || (int)json[index + 3] != 108) { return(0); } index += 4; return(11); } }
protected static string ParseString(char[] json, ref int index, ref bool success) { StringBuilder stringBuilder = new StringBuilder(); JsonParser.EatWhitespace(json, ref index); char c = json[index++]; bool flag = false; while (!flag && index != json.Length) { c = json[index++]; if (c == '"') { flag = true; break; } if (c == '\\') { if (index == json.Length) { break; } c = json[index++]; if (c == '"') { stringBuilder.Append('"'); } else if (c == '\\') { stringBuilder.Append('\\'); } else if (c == '/') { stringBuilder.Append('/'); } else if (c == 'b') { stringBuilder.Append('\b'); } else if (c == 'f') { stringBuilder.Append('\f'); } else if (c == 'n') { stringBuilder.Append('\n'); } else if (c == 'r') { stringBuilder.Append('\r'); } else if (c == 't') { stringBuilder.Append('\t'); } else if (c == 'u') { int num = json.Length - index; if (num < 4) { break; } uint utf; if (!(success = uint.TryParse(new string(json, index, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out utf))) { return(""); } stringBuilder.Append(char.ConvertFromUtf32((int)utf)); index += 4; } } else { stringBuilder.Append(c); } } if (!flag) { success = false; return(null); } return(stringBuilder.ToString()); }
protected static string ParseString(char[] json, ref int index, ref bool success) { StringBuilder stringBuilder = new StringBuilder(); JsonParser.EatWhitespace(json, ref index); char ch1 = json[index++]; bool flag = false; while (!flag && index != json.Length) { char ch2 = json[index++]; switch (ch2) { case '"': flag = true; goto label_19; case '\\': if (index != json.Length) { switch (json[index++]) { case '"': stringBuilder.Append('"'); continue; case '/': stringBuilder.Append('/'); continue; case '\\': stringBuilder.Append('\\'); continue; case 'b': stringBuilder.Append('\b'); continue; case 'f': stringBuilder.Append('\f'); continue; case 'n': stringBuilder.Append('\n'); continue; case 'r': stringBuilder.Append('\r'); continue; case 't': stringBuilder.Append('\t'); continue; case 'u': if (json.Length - index >= 4) { uint result; if (!(success = uint.TryParse(new string(json, index, 4), NumberStyles.HexNumber, (IFormatProvider)CultureInfo.InvariantCulture, out result))) { return(""); } stringBuilder.Append(char.ConvertFromUtf32((int)result)); index += 4; continue; } goto label_19; default: continue; } } else { goto label_19; } default: stringBuilder.Append(ch2); continue; } } label_19: if (flag) { return(stringBuilder.ToString()); } success = false; return((string)null); }