HtmlTextStream has now pt::Stream as a based class and uses pt::WTextStream as a buffer

This commit is contained in:
2021-07-16 18:17:57 +02:00
parent ba6159964b
commit c5c02d7f44
14 changed files with 764 additions and 375 deletions

View File

@@ -946,20 +946,11 @@ void SetMinMax(IntType & val, IntType min_val, IntType max_val)
}
template<class Stream, class StringType>
void JSONescape(Stream & out, const StringType & str)
template<class Stream>
void JSONescape(wchar_t c, Stream & out)
{
// !! IMPROVE ME (optimizing)
// it is better to not write one by one character
// but use write method insted
for(size_t i=0 ; i<str.size() ; ++i)
switch( c )
{
switch(str[i])
{
case 0: out << '\\'; out << '0'; break;
case '\r': out << '\\'; out << 'r'; break;
case '\n': out << '\\'; out << 'n'; break;
@@ -970,12 +961,31 @@ void JSONescape(Stream & out, const StringType & str)
//case '/': out << '\\'; out << '/'; break; // slash doesn't have to be escaped
case '"': out << '\\'; out << '\"'; break;
default:
out << str[i];
out << c;
}
}
template<class StringType, class Stream>
void JSONescape(const StringType & str, Stream & out)
{
for(size_t i=0 ; i < str.size() ; ++i)
{
if constexpr(sizeof(char) == sizeof(typename StringType::value_type))
{
JSONescape(static_cast<wchar_t>(static_cast<unsigned char>(str[i])), out);
}
else
{
JSONescape(str[i], out);
}
}
}
void JSONescapeStream(const pt::WTextStream & in, pt::WTextStream & out);
/*
* converting from a wide string to an UTF-8 string