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

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2008-2014, Tomasz Sowa
* Copyright (c) 2008-2021, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,38 +41,37 @@ namespace Winix
namespace TemplatesFunctions
{
// not thread safe
static std::string qencode_tmp;
void fil_urlencode(Info & i)
{
UrlEncode(i.in.Str(), i.out);
UrlEncode(i.in.get_buffer(), i.out.get_buffer(), false);
}
void fil_qencode(Info & i)
{
QEncode(i.in.Str(), qencode_tmp);
std::wstring tmp_str;
std::string qencode_tmp;
i.in.to_str(tmp_str);
QEncode(tmp_str, qencode_tmp);
i.out << R(qencode_tmp);
}
void fil_capitalize(Info & i)
{
const std::wstring & str = i.in.Str();
for(size_t a=0 ; a<str.size() ; ++a)
i.out << R(locale.ToCapital(str[a]));
for(size_t a=0 ; a < i.in.size() ; ++a)
i.out << R(locale.ToCapital(i.in.get_wchar(a)));
}
void fil_tosmall(Info & i)
{
const std::wstring & str = i.in.Str();
for(size_t a=0 ; a<str.size() ; ++a)
i.out << R(locale.ToSmall(str[a]));
for(size_t a=0 ; a < i.in.size() ; ++a)
i.out << R(locale.ToSmall(i.in.get_wchar(a)));
}
@@ -80,23 +79,24 @@ void fil_tosmall(Info & i)
void fil_firstup(Info & i)
{
bool was_dot = true;
const std::wstring & str = i.in.Str();
for(size_t a=0 ; a<str.size() ; ++a)
for(size_t a=0 ; a < i.in.size() ; ++a)
{
wchar_t c = i.in.get_wchar(a);
if( was_dot )
{
if( str[a]!=' ' && str[a]!='\t' && str[a]!=13 && str[a]!=10 && str[a]!=160 )
if( c!=' ' && c!='\t' && c!=13 && c!=10 && c!=160 )
was_dot = false;
i.out << R(locale.ToCapital(str[a]));
i.out << R(locale.ToCapital(c));
}
else
{
i.out << R(str[a]);
i.out << R(c);
}
if( str[a] == '.' )
if( c == '.' )
was_dot = true;
}
}
@@ -106,29 +106,32 @@ void fil_firstup(Info & i)
void fil_first_wordup(Info & i)
{
bool was_white = true;
const std::wstring & str = i.in.Str();
for(size_t a=0 ; a<str.size() ; ++a)
for(size_t a=0 ; a < i.in.size() ; ++a)
{
wchar_t c = i.in.get_wchar(a);
if( was_white )
{
i.out << R(locale.ToCapital(str[a]));
i.out << R(locale.ToCapital(c));
}
else
{
i.out << R(str[a]);
i.out << R(c);
}
was_white = (str[a]==' ' || str[a]=='\t' || str[a]==13 || str[a]==10 || str[a]==160);
was_white = (c==' ' || c=='\t' || c==13 || c==10 || c==160);
}
}
bool fil_csv_has_colon_or_quote(const std::wstring & str)
bool fil_csv_has_colon_or_quote(const pt::WTextStream & str)
{
for(size_t i=0 ; i<str.size() ; ++i)
{
if( str[i] == ',' || str[i] == '"' )
wchar_t c = str.get_wchar(i);
if( c == ',' || c == '"' )
return true;
}
@@ -139,25 +142,25 @@ return false;
void fil_csv_escape(Info & i)
{
const std::wstring & str = i.in.Str();
if( fil_csv_has_colon_or_quote(str) )
if( fil_csv_has_colon_or_quote(i.in.get_buffer()) )
{
i.out << R("\"");
for(size_t a=0 ; a<str.size() ; ++a)
for(size_t a=0 ; a < i.in.size() ; ++a)
{
if( str[a] == '"' )
wchar_t c = i.in.get_wchar(a);
if( c == '"' )
i.out << R("\"\"");
else
i.out << R(str[a]);
i.out << R(c);
}
i.out << R("\"");
}
else
{
i.out << R(str);
i.out << i.in;
}
}
@@ -165,14 +168,14 @@ void fil_csv_escape(Info & i)
void fil_new_line_to_br(Info & i)
{
const std::wstring & str = i.in.Str();
for(size_t a=0 ; a<str.size() ; ++a)
for(size_t a=0 ; a < i.in.size() ; ++a)
{
if( str[a] == '\n' )
wchar_t c = i.in.get_wchar(a);
if( c == '\n' )
i.out << R("<br>\n");
else
i.out << R(str[a]);
i.out << R(c);
}
}
@@ -184,17 +187,17 @@ void fil_new_line_to_br(Info & i)
*/
void fil_html_quote(Info & i)
{
const std::wstring & str = i.in.Str();
for(size_t a=0 ; a<str.size() ; ++a)
for(size_t a=0 ; a < i.in.size() ; ++a)
{
if( str[a] == '\"' )
wchar_t c = i.in.get_wchar(a);
if( c == '\"' )
i.out << R("&quot;");
else
if( str[a] == '\'' )
if( c == '\'' )
i.out << R("&#39;");
else
i.out << R(str[a]);
i.out << R(c);
}
}
@@ -205,17 +208,17 @@ void fil_html_quote(Info & i)
*/
void fil_html_newline(Info & i)
{
const std::wstring & str = i.in.Str();
for(size_t a=0 ; a<str.size() ; ++a)
for(size_t a=0 ; a < i.in.size() ; ++a)
{
if( str[a] == 10 )
wchar_t c = i.in.get_wchar(a);
if( c == 10 )
i.out << R("&#10;");
else
if( str[a] == 13 )
if( c == 13 )
i.out << R("&#13;");
else
i.out << R(str[a]);
i.out << R(c);
}
}