mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-31 01:11:12 +02:00
fix json unicode output
This commit is contained in:
@@ -296,6 +296,53 @@ std::string json_out_error(std::string _error) {
|
||||
// JSON: convert string to JSON-String
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
std::string json_convert_string(std::string value)
|
||||
{
|
||||
std::string result;
|
||||
for (size_t i = 0; i < value.length(); i++)
|
||||
{
|
||||
unsigned char c = unsigned(value[i]);
|
||||
switch(c)
|
||||
{
|
||||
case '\"':
|
||||
result += "\\\"";
|
||||
break;
|
||||
case '\\':
|
||||
result += "\\\\";
|
||||
break;
|
||||
case '\b':
|
||||
result += "\\b";
|
||||
break;
|
||||
case '\f':
|
||||
result += "\\f";
|
||||
break;
|
||||
case '\n':
|
||||
result += "\\n";
|
||||
break;
|
||||
case '\r':
|
||||
result += "\\r";
|
||||
break;
|
||||
case '\t':
|
||||
result += "\\t";
|
||||
break;
|
||||
default:
|
||||
if ( isControlCharacter( c ) )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(c);
|
||||
result += oss.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::string json_convert_string(std::string s) {
|
||||
std::stringstream ss;
|
||||
for (size_t i = 0; i < s.length(); ) {
|
||||
@@ -350,6 +397,7 @@ std::string json_convert_string(std::string s) {
|
||||
}
|
||||
return ss.str();
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
std::string yExecuteScript(std::string cmd) {
|
||||
std::string script, para, result;
|
||||
|
@@ -48,6 +48,8 @@ std::string json_out_pair(std::string _key, std::string _value);
|
||||
std::string json_out_success(std::string _result);
|
||||
std::string json_out_error(std::string _error);
|
||||
std::string json_convert_string(std::string s);
|
||||
/// Returns true if ch is a control character (in range [0,32]).
|
||||
static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F;}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Script Helpers
|
||||
|
Reference in New Issue
Block a user