mirror of https://github.com/aria2/aria2
Removed unused code
parent
2ca98cc428
commit
aa6f9c2057
78
src/json.cc
78
src/json.cc
|
@ -521,84 +521,6 @@ std::string jsonEscape(const std::string& s)
|
|||
return t;
|
||||
}
|
||||
|
||||
std::string encode(const ValueBase* vlb)
|
||||
{
|
||||
class JsonValueBaseVisitor:public ValueBaseVisitor {
|
||||
private:
|
||||
std::ostringstream out_;
|
||||
public:
|
||||
virtual void visit(const String& string)
|
||||
{
|
||||
const std::string& s = string.s();
|
||||
std::string t = jsonEscape(s);
|
||||
out_ << '"';
|
||||
out_.write(t.data(), t.size());
|
||||
out_ << '"';
|
||||
}
|
||||
|
||||
virtual void visit(const Integer& integer)
|
||||
{
|
||||
out_ << integer.i();
|
||||
}
|
||||
|
||||
virtual void visit(const Bool& boolValue)
|
||||
{
|
||||
out_ << (boolValue.val() ? "true" : "false");
|
||||
}
|
||||
|
||||
virtual void visit(const Null& nullValue)
|
||||
{
|
||||
out_ << "null";
|
||||
}
|
||||
|
||||
virtual void visit(const List& list)
|
||||
{
|
||||
out_ << '[';
|
||||
List::ValueType::const_iterator i = list.begin();
|
||||
if(!list.empty()) {
|
||||
(*i)->accept(*this);
|
||||
}
|
||||
++i;
|
||||
for(List::ValueType::const_iterator eoi = list.end(); i != eoi; ++i){
|
||||
out_ << ',';
|
||||
(*i)->accept(*this);
|
||||
}
|
||||
out_ << ']';
|
||||
}
|
||||
|
||||
virtual void visit(const Dict& dict)
|
||||
{
|
||||
out_ << '{';
|
||||
Dict::ValueType::const_iterator i = dict.begin();
|
||||
if(!dict.empty()) {
|
||||
std::string key = jsonEscape((*i).first);
|
||||
out_ << '"';
|
||||
out_.write(key.data(), key.size());
|
||||
out_ << "\":";
|
||||
(*i).second->accept(*this);
|
||||
}
|
||||
++i;
|
||||
for(Dict::ValueType::const_iterator eoi = dict.end(); i != eoi; ++i){
|
||||
out_ << ',';
|
||||
std::string key = jsonEscape((*i).first);
|
||||
out_ << '"';
|
||||
out_.write(key.data(), key.size());
|
||||
out_ << "\":";
|
||||
(*i).second->accept(*this);
|
||||
}
|
||||
out_ << '}';
|
||||
}
|
||||
|
||||
std::string getResult() const
|
||||
{
|
||||
return out_.str();
|
||||
}
|
||||
};
|
||||
JsonValueBaseVisitor visitor;
|
||||
vlb->accept(visitor);
|
||||
return visitor.getResult();
|
||||
}
|
||||
|
||||
// Serializes JSON object or array.
|
||||
std::string encode(const SharedHandle<ValueBase>& json)
|
||||
{
|
||||
|
|
|
@ -127,7 +127,6 @@ OutputStream& encode(OutputStream& out, const SharedHandle<ValueBase>& vlb)
|
|||
}
|
||||
|
||||
// Serializes JSON object or array.
|
||||
std::string encode(const ValueBase* json);
|
||||
std::string encode(const SharedHandle<ValueBase>& json);
|
||||
|
||||
struct JsonGetParam {
|
||||
|
|
|
@ -413,43 +413,43 @@ void JsonTest::testDecode_error()
|
|||
void JsonTest::testEncode()
|
||||
{
|
||||
{
|
||||
Dict dict;
|
||||
dict["name"] = String::g("aria2");
|
||||
dict["loc"] = Integer::g(80000);
|
||||
SharedHandle<Dict> dict = Dict::g();
|
||||
dict->put("name", String::g("aria2"));
|
||||
dict->put("loc", Integer::g(80000));
|
||||
SharedHandle<List> files = List::g();
|
||||
files->append(String::g("aria2c"));
|
||||
dict["files"] = files;
|
||||
dict->put("files", files);
|
||||
SharedHandle<Dict> attrs = Dict::g();
|
||||
attrs->put("license", String::g("GPL"));
|
||||
dict["attrs"] = attrs;
|
||||
dict->put("attrs", attrs);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("{\"attrs\":{\"license\":\"GPL\"},"
|
||||
"\"files\":[\"aria2c\"],"
|
||||
"\"loc\":80000,"
|
||||
"\"name\":\"aria2\"}"),
|
||||
json::encode(&dict));
|
||||
json::encode(dict));
|
||||
}
|
||||
{
|
||||
List list;
|
||||
list.append("\"\\/\b\f\n\r\t");
|
||||
SharedHandle<List> list = List::g();
|
||||
list->append("\"\\/\b\f\n\r\t");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[\"\\\"\\\\\\/\\b\\f\\n\\r\\t\"]"),
|
||||
json::encode(&list));
|
||||
json::encode(list));
|
||||
}
|
||||
{
|
||||
List list;
|
||||
SharedHandle<List> list = List::g();
|
||||
std::string s;
|
||||
s += 0x1Fu;
|
||||
list.append(s);
|
||||
list->append(s);
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[\"\\u001F\"]"),
|
||||
json::encode(&list));
|
||||
json::encode(list));
|
||||
}
|
||||
{
|
||||
List list;
|
||||
list.append(Bool::gTrue());
|
||||
list.append(Bool::gFalse());
|
||||
list.append(Null::g());
|
||||
SharedHandle<List> list = List::g();
|
||||
list->append(Bool::gTrue());
|
||||
list->append(Bool::gFalse());
|
||||
list->append(Null::g());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("[true,false,null]"),
|
||||
json::encode(&list));
|
||||
json::encode(list));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue