Removed unused code

pull/2/head
Tatsuhiro Tsujikawa 2011-11-08 23:13:47 +09:00
parent 2ca98cc428
commit aa6f9c2057
3 changed files with 17 additions and 96 deletions

View File

@ -521,84 +521,6 @@ std::string jsonEscape(const std::string& s)
return t; 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. // Serializes JSON object or array.
std::string encode(const SharedHandle<ValueBase>& json) std::string encode(const SharedHandle<ValueBase>& json)
{ {

View File

@ -127,7 +127,6 @@ OutputStream& encode(OutputStream& out, const SharedHandle<ValueBase>& vlb)
} }
// Serializes JSON object or array. // Serializes JSON object or array.
std::string encode(const ValueBase* json);
std::string encode(const SharedHandle<ValueBase>& json); std::string encode(const SharedHandle<ValueBase>& json);
struct JsonGetParam { struct JsonGetParam {

View File

@ -413,43 +413,43 @@ void JsonTest::testDecode_error()
void JsonTest::testEncode() void JsonTest::testEncode()
{ {
{ {
Dict dict; SharedHandle<Dict> dict = Dict::g();
dict["name"] = String::g("aria2"); dict->put("name", String::g("aria2"));
dict["loc"] = Integer::g(80000); dict->put("loc", Integer::g(80000));
SharedHandle<List> files = List::g(); SharedHandle<List> files = List::g();
files->append(String::g("aria2c")); files->append(String::g("aria2c"));
dict["files"] = files; dict->put("files", files);
SharedHandle<Dict> attrs = Dict::g(); SharedHandle<Dict> attrs = Dict::g();
attrs->put("license", String::g("GPL")); attrs->put("license", String::g("GPL"));
dict["attrs"] = attrs; dict->put("attrs", attrs);
CPPUNIT_ASSERT_EQUAL(std::string("{\"attrs\":{\"license\":\"GPL\"}," CPPUNIT_ASSERT_EQUAL(std::string("{\"attrs\":{\"license\":\"GPL\"},"
"\"files\":[\"aria2c\"]," "\"files\":[\"aria2c\"],"
"\"loc\":80000," "\"loc\":80000,"
"\"name\":\"aria2\"}"), "\"name\":\"aria2\"}"),
json::encode(&dict)); json::encode(dict));
} }
{ {
List list; SharedHandle<List> list = List::g();
list.append("\"\\/\b\f\n\r\t"); list->append("\"\\/\b\f\n\r\t");
CPPUNIT_ASSERT_EQUAL(std::string("[\"\\\"\\\\\\/\\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; std::string s;
s += 0x1Fu; s += 0x1Fu;
list.append(s); list->append(s);
CPPUNIT_ASSERT_EQUAL(std::string("[\"\\u001F\"]"), CPPUNIT_ASSERT_EQUAL(std::string("[\"\\u001F\"]"),
json::encode(&list)); json::encode(list));
} }
{ {
List list; SharedHandle<List> list = List::g();
list.append(Bool::gTrue()); list->append(Bool::gTrue());
list.append(Bool::gFalse()); list->append(Bool::gFalse());
list.append(Null::g()); list->append(Null::g());
CPPUNIT_ASSERT_EQUAL(std::string("[true,false,null]"), CPPUNIT_ASSERT_EQUAL(std::string("[true,false,null]"),
json::encode(&list)); json::encode(list));
} }
} }