protected static double parseNumber(char[] json, ref int index) { MiniJSON.eatWhitespace(json, ref index); int lastIndexOfNumber = MiniJSON.getLastIndexOfNumber(json, index); int num = lastIndexOfNumber - index + 1; char[] array = new char[num]; Array.Copy(json, index, array, 0, num); index = lastIndexOfNumber + 1; return(double.Parse(new string(array))); }
protected static int nextToken(char[] json, ref int index) { MiniJSON.eatWhitespace(json, ref index); if (index == json.Length) { return(0); } char c = json[index]; index++; switch (c) { 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); default: switch (c) { case '[': return(3); default: switch (c) { case '{': return(1); default: { if (c == '"') { return(7); } 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); } case '}': return(2); } break; case ']': return(4); } break; case ':': return(5); } }
protected static string parseString(char[] json, ref int index) { string text = string.Empty; MiniJSON.eatWhitespace(json, ref index); char c = json[index++]; bool flag = false; while (!flag) { if (index == json.Length) { break; } c = json[index++]; if (c == '"') { flag = true; break; } if (c == '\\') { if (index == json.Length) { break; } c = json[index++]; if (c == '"') { text += '"'; } else if (c == '\\') { text += '\\'; } else if (c == '/') { text += '/'; } else if (c == 'b') { text += '\b'; } else if (c == 'f') { text += '\f'; } else if (c == 'n') { text += '\n'; } else if (c == 'r') { text += '\r'; } else if (c == 't') { text += '\t'; } else if (c == 'u') { int num = json.Length - index; if (num < 4) { break; } char[] array = new char[4]; Array.Copy(json, index, array, 0, 4); uint utf = uint.Parse(new string(array), NumberStyles.HexNumber); text += char.ConvertFromUtf32((int)utf); index += 4; } } else { text += c; } } if (!flag) { return(null); } return(text); }