dot 言語や jsonの出力に使うために以下のようなエスケープを行ってくれる関数を使っている。
|
// 文字列を受け取り、ダブルクオーテーションや改行などをエスケープする |
|
// https://stackoverflow.com/questions/7724448/simple-json-string-escape-for-c |
|
std::string escape(const std::string &s) { |
|
std::ostringstream o; |
|
for (auto c = s.cbegin(); c != s.cend(); c++) { |
|
if (*c == '"' || *c == '\\' || ('\x00' <= *c && *c <= '\x1f')) { |
|
o << "\\u" |
|
<< std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(*c); |
|
} else { |
|
o << *c; |
|
} |
|
} |
|
return o.str(); |
|
} |
しかし、{
, }
, |
, >
, <
がエスケープ対象から漏れているため、dot言語の出力が崩れる場合がある。修正が必要