JsonValue ReadCore(bool objectWithoutBraces = false) { int c = objectWithoutBraces?'{':SkipPeekChar(); if (c < 0) { throw ParseError("Incomplete input"); } switch (c) { case '[': JsonArray list; WscJsonArray wscL = null; ReadChar(); ResetWhite(); if (ReadWsc) { list = wscL = new WscJsonArray(); } else { list = new JsonArray(); } SkipPeekChar(); if (ReadWsc) { wscL.Comments.Add(GetWhite()); } for (int i = 0; ; i++) { if (SkipPeekChar() == ']') { ReadChar(); break; } if (HasReader) { Reader.Index(i); } var value = ReadCore(); if (HasReader) { Reader.Value(value); } list.Add(value); ResetWhite(); if (SkipPeekChar() == ',') { ReadChar(); ResetWhite(); SkipPeekChar(); } if (ReadWsc) { wscL.Comments.Add(GetWhite()); } } return(list); case '{': JsonObject obj; WscJsonObject wsc = null; if (!objectWithoutBraces) { ReadChar(); ResetWhite(); } if (ReadWsc) { obj = wsc = new WscJsonObject() { RootBraces = !objectWithoutBraces } } ; else { obj = new JsonObject(); } SkipPeekChar(); if (ReadWsc) { wsc.Comments[""] = GetWhite(); } for (; ;) { if (objectWithoutBraces) { if (SkipPeekChar() < 0) { break; } } else if (SkipPeekChar() == '}') { ReadChar(); break; } string name = readKeyName(); skipWhite2(); Expect(':'); skipWhite2(); if (HasReader) { Reader.Key(name); } var value = ReadCore(); if (HasReader) { Reader.Value(value); } obj.Add(new JsonPair(name, value)); ResetWhite(); if (SkipPeekChar() == ',') { ReadChar(); ResetWhite(); SkipPeekChar(); } if (ReadWsc) { wsc.Comments[name] = GetWhite(); wsc.Order.Add(name); } } return(obj); case '\'': case '"': return(ReadStringLiteral(readMlString)); default: return(readTfnns(c)); } }
JsonValue ReadCore() { int c = SkipPeekChar(), next; if (c < 0) { throw ParseError("Incomplete input"); } switch (c) { case '[': JsonArray list; WscJsonArray wscL = null; ReadChar(); ResetWhite(); if (ReadWsc) { list = wscL = new WscJsonArray(); } else { list = new JsonArray(); } next = SkipPeekChar(); if (ReadWsc) { wscL.Comments.Add(GetWhite()); } if (next == ']') { ReadChar(); return(list); } for (int i = 0; ; i++) { if (HasReader) { Reader.Index(i); } var value = ReadCore(); if (HasReader) { Reader.Value(value); } list.Add(value); ResetWhite(); c = SkipPeekChar(); if (c == ',') { ReadChar(); ResetWhite(); c = SkipPeekChar(); } if (ReadWsc) { wscL.Comments.Add(GetWhite()); } if (c == ']') { ReadChar(); break; } } return(list); case '{': JsonObject obj; WscJsonObject wsc = null; ReadChar(); ResetWhite(); if (ReadWsc) { obj = wsc = new WscJsonObject(); } else { obj = new JsonObject(); } next = SkipPeekChar(); if (ReadWsc) { wsc.Comments[""] = GetWhite(); } if (next == '}') { ReadChar(); return(obj); } for (; ;) { if (SkipPeekChar() == '}') { ReadChar(); break; } string name = readName(); skipWhite2(); Expect(':'); skipWhite2(); if (HasReader) { Reader.Key(name); } var value = ReadCore(); if (HasReader) { Reader.Value(value); } obj.Add(new JsonPair(name, value)); ResetWhite(); c = SkipPeekChar(); if (c == ',') { ReadChar(); ResetWhite(); c = SkipPeekChar(); } if (ReadWsc) { wsc.Comments[name] = GetWhite(); wsc.Order.Add(name); } if (c == '}') { ReadChar(); break; } } return(obj); case '-': return(ReadNumericLiteral()); default: return(readPrimitive(c)); } }