IValue* Decoder::_decode(std::string value, int &pos) { IValue* json; std::string str = value.substr(pos); if (str.length() > 0) { switch(str[0]) { case '{': { int startPos = 0; json = new Value::Object(); (dynamic_cast<Value::Object*>(json))->set(Decoder::_decodeObject(str, startPos)); pos += startPos; } break; case '"': json = new Value::String(); json->set(Decoder::_decodeString(str)); pos += (json->getString().length() + 2); break; case '[': { int startPos = 0; json = new Value::Array(); (dynamic_cast<Value::Array*>(json))->set(Decoder::_decodeArray(str, startPos)); pos += startPos; } break; case 't': case 'f': json = new Value::Boolean(); (dynamic_cast<Value::Boolean*>(json))->set(Decoder::_decodeBoolean(str)); if (value[pos] == 't') { pos += 4; } else { pos += 5; } break; case 'n': json = new Value::Null(); Decoder::_decodeNull(str); pos += 4; break; default: { int startPos = 0; json = new Value::Numeric(); (dynamic_cast<Value::Numeric*>(json))->set(Decoder::_decodeNumeric(str, startPos)); pos += startPos; } } } return json; }