Code cleanup

pull/1/head
Tatsuhiro Tsujikawa 2011-03-16 12:56:03 +09:00
parent 15730aa560
commit 046bee87a2
1 changed files with 10 additions and 13 deletions

View File

@ -56,11 +56,7 @@ OutputStream& encode(OutputStream& out, const ValueBase* vlb)
virtual void visit(const String& string) virtual void visit(const String& string)
{ {
const std::string& s = string.s(); encodeString(string.s());
std::string t = jsonEscape(s);
out_ << "\"";
out_.write(t.data(), t.size());
out_ << "\"";
} }
virtual void visit(const Integer& integer) virtual void visit(const Integer& integer)
@ -98,24 +94,25 @@ OutputStream& encode(OutputStream& out, const ValueBase* vlb)
out_ << "{"; out_ << "{";
Dict::ValueType::const_iterator i = dict.begin(); Dict::ValueType::const_iterator i = dict.begin();
if(!dict.empty()) { if(!dict.empty()) {
std::string key = jsonEscape((*i).first); encodeString((*i).first);
out_ << "\""; out_ << ":";
out_.write(key.data(), key.size());
out_ << "\":";
(*i).second->accept(*this); (*i).second->accept(*this);
++i; ++i;
for(Dict::ValueType::const_iterator eoi = dict.end(); i != eoi; ++i){ for(Dict::ValueType::const_iterator eoi = dict.end(); i != eoi; ++i){
out_ << ","; out_ << ",";
std::string key = jsonEscape((*i).first); encodeString((*i).first);
out_ << "\""; out_ << ":";
out_.write(key.data(), key.size());
out_ << "\":";
(*i).second->accept(*this); (*i).second->accept(*this);
} }
} }
out_ << "}"; out_ << "}";
} }
private: private:
void encodeString(const std::string& s)
{
std::string t = jsonEscape(s);
out_ << "\"" << t << "\"";
}
OutputStream& out_; OutputStream& out_;
}; };
JsonValueBaseVisitor visitor(out); JsonValueBaseVisitor visitor(out);