summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2011-03-08 18:48:51 -0500
committerChris Dyer <cdyer@cs.cmu.edu>2011-03-08 18:48:51 -0500
commit3362e40b046c2e064e49f38d5997abc65bcc9a54 (patch)
treee6b48d7118fb1391c1fe21654d5bb110588f2770
parenta8666b26f9d1ad60872d4572e73234d033c53d0d (diff)
fix to json-escape feature names in hg json encoding
-rw-r--r--decoder/hg_io.cc10
1 files changed, 6 insertions, 4 deletions
diff --git a/decoder/hg_io.cc b/decoder/hg_io.cc
index 1af8261e..c1c93933 100644
--- a/decoder/hg_io.cc
+++ b/decoder/hg_io.cc
@@ -282,7 +282,8 @@ bool HypergraphIO::WriteToJSON(const Hypergraph& hg, bool remove_rules, ostream*
if (use_fdict) {
o << "\"features\":[";
for (int i = 1; i < FD::NumFeats(); ++i) {
- o << (i==1 ? "":",") << '"' << FD::Convert(i) << '"';
+ o << (i==1 ? "":",");
+ JSONParser::WriteEscapedString(FD::Convert(i), &o);
}
o << "],";
}
@@ -314,9 +315,10 @@ bool HypergraphIO::WriteToJSON(const Hypergraph& hg, bool remove_rules, ostream*
if (!first) o << ',';
if (use_fdict)
o << (it->first - 1);
- else
- o << '"' << FD::Convert(it->first) << '"';
- o << ',' << it->second;
+ else {
+ JSONParser::WriteEscapedString(FD::Convert(it->first), &o);
+ }
+ o << ',' << it->second;
first = false;
}
o << "]";