1
This commit is contained in:
parent
e0cc2d0834
commit
0908b71e83
@ -24,7 +24,7 @@ namespace a8
|
||||
return obj;
|
||||
}
|
||||
|
||||
a8::MutableXObject& MutableXObject::SetVal(int i, a8::XValue val)
|
||||
a8::MutableXObject& MutableXObject::Push(a8::XValue val)
|
||||
{
|
||||
if (type_ != XOT_ARRAY) {
|
||||
abort();
|
||||
@ -33,13 +33,13 @@ namespace a8
|
||||
return *this;
|
||||
}
|
||||
|
||||
a8::MutableXObject& MutableXObject::SetVal(int i, a8::MutableXObject&& val)
|
||||
a8::MutableXObject& MutableXObject::Push(a8::MutableXObject& val)
|
||||
{
|
||||
if (type_ != XOT_ARRAY) {
|
||||
abort();
|
||||
}
|
||||
std::shared_ptr<a8::XObject> p = std::make_shared<a8::XObject>();
|
||||
*p.get() = val;
|
||||
val.Move(*p.get());
|
||||
value_.array_value->push_back(p);
|
||||
return *this;
|
||||
}
|
||||
|
@ -14,8 +14,8 @@ namespace a8
|
||||
static a8::MutableXObject* NewObject();
|
||||
static a8::MutableXObject* NewArray();
|
||||
|
||||
a8::MutableXObject& SetVal(int i, a8::XValue val);
|
||||
a8::MutableXObject& SetVal(int i, a8::MutableXObject&& val);
|
||||
a8::MutableXObject& Push(a8::XValue val);
|
||||
a8::MutableXObject& Push(a8::MutableXObject& val);
|
||||
a8::MutableXObject& SetVal(const std::string& key, a8::XValue val);
|
||||
a8::MutableXObject& SetVal(const std::string& key, a8::XObject& val);
|
||||
a8::MutableXObject& SetVal(const std::string& key, a8::MutableXObject& val);
|
||||
|
@ -107,6 +107,16 @@ namespace a8
|
||||
}
|
||||
}
|
||||
|
||||
a8::XValue XObject::Get(const std::string& key, a8::XValue defval)
|
||||
{
|
||||
if (type_ == XOT_OBJECT) {
|
||||
auto itr = value_.object_value->find(key);
|
||||
return itr != value_.object_value->end() ? itr->second->AsXValue() : defval;
|
||||
} else {
|
||||
return defval;
|
||||
}
|
||||
}
|
||||
|
||||
bool XObject::HasKey(const std::string& key)
|
||||
{
|
||||
assert(type_ == XOT_OBJECT);
|
||||
@ -211,6 +221,29 @@ namespace a8
|
||||
return true;
|
||||
}
|
||||
|
||||
void XObject::ReadFromUrlQueryString(const std::string& query_string)
|
||||
{
|
||||
type_ = a8::XOT_OBJECT;
|
||||
value_.object_value = new std::map<std::string, std::shared_ptr<a8::XObject>>();
|
||||
|
||||
std::vector<std::string> params;
|
||||
a8::Split(query_string, params, '&');
|
||||
for(unsigned int i = 0; i < params.size(); i++){
|
||||
int pos = params[i].find('=');
|
||||
if(pos > 0){
|
||||
std::string key = params[i].substr(0, pos);
|
||||
std::string val = params[i].substr(pos + 1, params[i].size() - pos);
|
||||
val = a8::UrlDecode(val);
|
||||
{
|
||||
std::shared_ptr<a8::XObject> xobj_ptr = std::make_shared<a8::XObject>();
|
||||
xobj_ptr->type_ = a8::XOT_SIMPLE;
|
||||
xobj_ptr->value_.x_value = new a8::XValue(val);
|
||||
(*value_.object_value)[key] = xobj_ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XObject::ToJsonStr(std::string& data)
|
||||
{
|
||||
if (type_ == a8::XOT_SIMPLE) {
|
||||
|
@ -33,6 +33,7 @@ namespace a8
|
||||
std::shared_ptr<a8::XObject> operator[] (const std::string& key);
|
||||
std::shared_ptr<a8::XObject> At(int i);
|
||||
std::shared_ptr<a8::XObject> At(const std::string& key);
|
||||
a8::XValue Get(const std::string& key, a8::XValue defval="");
|
||||
bool HasKey(const std::string& key);
|
||||
bool HasKey(int i);
|
||||
const a8::XObject& operator=(const a8::XObject& obj);
|
||||
@ -42,6 +43,7 @@ namespace a8
|
||||
bool ReadFromJsonString(const std::string& jsondata);
|
||||
bool ReadFromXmlFile(const std::string& filename);
|
||||
bool ReadFromXmlString(const std::string& xmldata);
|
||||
void ReadFromUrlQueryString(const std::string& query_string);
|
||||
void ToJsonStr(std::string& data);
|
||||
void ToUrlEncodeStr(std::string& data);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user