improve the Space text convertion methods
Read the whole character from a multibyte string (as int/char32_t) and then check if it needs to be escaped. Also don't use a tmp stream object when serializing between wide/char strings. while here: - add try_esc_to_space(...) global function - add wide_to_output_function(const wchar_t * str, size_t len, OutputFunction output_function, int mode) - add wide_to_output_function(const wchar_t * str, OutputFunction output_function, int mode)
This commit is contained in:
@@ -525,6 +525,58 @@ bool try_esc_to_html(char32_t c, pt::Stream & out)
|
||||
}
|
||||
|
||||
|
||||
bool try_esc_to_space(char32_t c, pt::Stream & out)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
switch(c)
|
||||
{
|
||||
case 0:
|
||||
out << '\\';
|
||||
out << 'u' << '{' << '0' << '}';
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case '\r': // 13
|
||||
out << '\\';
|
||||
out << 'r';
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case '\n': // 10
|
||||
out << '\\';
|
||||
out << 'n';
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
out << '\\';
|
||||
out << '\\';
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case '"':
|
||||
out << '\\';
|
||||
out << '\"';
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case '\b': // 8
|
||||
out << '\\';
|
||||
out << 'b';
|
||||
status = true;
|
||||
break;
|
||||
|
||||
case '\f': // 12
|
||||
out << '\\';
|
||||
out << 'f';
|
||||
status = true;
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user