1
0
mirror of https://github.com/pdf2htmlEX/pdf2htmlEX.git synced 2024-07-03 08:38:39 +00:00

add json encoding

This commit is contained in:
Lu Wang 2013-05-09 20:30:49 +08:00
parent 57a687ccf8
commit de26cf056e
3 changed files with 25 additions and 1 deletions

View File

@ -457,7 +457,7 @@ void HTMLRenderer::post_process(void)
if(iter != page_filenames.begin())
output << ",";
output << "'";
outputURL(output, *iter);
outputJSON(output, *iter);
output << "'";
}
}

View File

@ -127,4 +127,23 @@ void outputURL(ostream & out, const string & s)
}
}
void outputJSON(ostream & out, const string & s)
{
for(auto iter = s.begin(); iter != s.end(); ++iter)
{
switch (*iter)
{
case '\\': out << "\\\\"; break;
case '"': out << "\\\""; break;
case '/': out << "\\/"; break;
case '\b': out << "\\b"; break;
case '\f': out << "\\f"; break;
case '\n': out << "\\n"; break;
case '\r': out << "\\r"; break;
case '\t': out << "\\t"; break;
default: out << *iter; break;
}
}
}
} //namespace pdf2htmlEX

View File

@ -25,6 +25,11 @@ void outputUnicodes(std::ostream & out, const Unicode * u, int uLen);
* URL encoding
*/
void outputURL(std::ostream & out, const std::string & s);
/*
* JSON encoding
*/
void outputJSON(std::ostream & out, const std::string & s);
} // namespace pdf2htmlEX