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:
2024-06-19 04:46:00 +02:00
parent c0838de3a4
commit f85f1dade5
6 changed files with 289 additions and 155 deletions

View File

@@ -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;
}
}