added: to HtmlTextStream: Escape(bool) method
now the output html streams can be turn into no-escaping mode default true (set when a request is clearing) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@990 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
8f8defe0de
commit
0ecb2ac70e
|
@ -71,12 +71,16 @@ size_t len = 16;
|
|||
if( len < 1 || len > 64 )
|
||||
len = 16;
|
||||
|
||||
if( out_streams.size() != len )
|
||||
out_streams.resize(len);
|
||||
|
||||
if( use_html_filter.size() != len )
|
||||
use_html_filter.resize(len);
|
||||
|
||||
for(size_t i=0 ; i<out_streams.size() ; ++i)
|
||||
{
|
||||
out_streams[i].Clear();
|
||||
out_streams[i].Escape(true);
|
||||
use_html_filter[i] = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ namespace Winix
|
|||
|
||||
HtmlTextStream::HtmlTextStream()
|
||||
{
|
||||
escape = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -226,6 +227,21 @@ HtmlTextStream & HtmlTextStream::operator<<(RawText<void*> raw)
|
|||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<PT::Space> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(RawText<PT::Date> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::Write(const char * buf, size_t len)
|
||||
|
@ -262,6 +278,11 @@ HtmlTextStream & HtmlTextStream::write(const wchar_t * buf, size_t len)
|
|||
*/
|
||||
|
||||
|
||||
void HtmlTextStream::Escape(bool escape_characters)
|
||||
{
|
||||
escape = escape_characters;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::ETextPutChar(char c)
|
||||
|
@ -293,7 +314,7 @@ HtmlTextStream & HtmlTextStream::ETextPutChar(wchar_t c)
|
|||
if( c == 13 )
|
||||
buffer += L" ";
|
||||
else
|
||||
if( c != 0 )
|
||||
if( c != 0 ) // !! CHECK ME may it should be changed to something like '�';
|
||||
buffer += c;
|
||||
|
||||
return *this;
|
||||
|
@ -380,19 +401,34 @@ HtmlTextStream & HtmlTextStream::EPutText(const std::wstring & str)
|
|||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const char * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::string * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::string & str)
|
||||
{
|
||||
return EPutText(str);
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -400,19 +436,34 @@ HtmlTextStream & HtmlTextStream::operator<<(const std::string & str)
|
|||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const wchar_t * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::wstring * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::wstring & str)
|
||||
{
|
||||
return EPutText(str);
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -420,7 +471,10 @@ HtmlTextStream & HtmlTextStream::operator<<(const std::wstring & str)
|
|||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(char v)
|
||||
{
|
||||
if( escape )
|
||||
ETextPutChar(v);
|
||||
else
|
||||
PutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -428,7 +482,10 @@ return *this;
|
|||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(wchar_t v)
|
||||
{
|
||||
if( escape )
|
||||
ETextPutChar(v);
|
||||
else
|
||||
PutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -436,6 +493,11 @@ return *this;
|
|||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(int v)
|
||||
{
|
||||
/*
|
||||
* int, long and others don't have to be escaped
|
||||
* (they consist of digits only: '0' - '9' and other characters which
|
||||
* don't have to be escaped)
|
||||
*/
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
|
@ -485,12 +547,23 @@ return *this;
|
|||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const PT::Space & space)
|
||||
{
|
||||
if( escape )
|
||||
{
|
||||
space.Serialize(*this, true, false);
|
||||
|
||||
/*
|
||||
tmp_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how many memory is needed beforehand
|
||||
space.Serialize(tmp_stream, true, false);
|
||||
operator<<(tmp_stream.Str());
|
||||
tmp_stream.Clear();
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(space);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
@ -498,12 +571,23 @@ return *this;
|
|||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const PT::Date & date)
|
||||
{
|
||||
if( escape )
|
||||
{
|
||||
date.Serialize(*this);
|
||||
|
||||
/*
|
||||
tmp_stream.Clear();
|
||||
// !! IMPROVE ME
|
||||
// we can calculate how many memory is needed beforehand
|
||||
date.Serialize(tmp_stream);
|
||||
operator<<(tmp_stream.Str());
|
||||
tmp_stream.Clear();
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(date);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -137,6 +137,8 @@ public:
|
|||
HtmlTextStream & operator<<(RawText<unsigned long> raw);
|
||||
HtmlTextStream & operator<<(RawText<double> raw);
|
||||
HtmlTextStream & operator<<(RawText<void*> raw);
|
||||
HtmlTextStream & operator<<(RawText<PT::Space> raw);
|
||||
HtmlTextStream & operator<<(RawText<PT::Date> raw);
|
||||
|
||||
template<typename arg_char_type, size_t arg_stack_size, size_t arg_heap_block_size>
|
||||
HtmlTextStream & operator<<(RawText<PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size> > raw);
|
||||
|
@ -168,6 +170,11 @@ public:
|
|||
HtmlTextStream & EPutText(const std::wstring * str);
|
||||
HtmlTextStream & EPutText(const std::wstring & str);
|
||||
|
||||
/*
|
||||
* by default all operator<< shown below use escaping
|
||||
* but you can turn it off by calling Escape(false)
|
||||
*/
|
||||
void Escape(bool escape_characters);
|
||||
|
||||
HtmlTextStream & operator<<(const char * str);
|
||||
HtmlTextStream & operator<<(const std::string * str);
|
||||
|
@ -192,8 +199,9 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
TextStream<std::wstring> tmp_stream;
|
||||
//TextStream<std::wstring> tmp_stream;
|
||||
std::wstring tmp_string;
|
||||
bool escape;
|
||||
|
||||
};
|
||||
|
||||
|
@ -213,8 +221,18 @@ HtmlTextStream & HtmlTextStream::operator<<(const PT::TextStreamBase<arg_char_ty
|
|||
{
|
||||
typename PT::TextStreamBase<arg_char_type, arg_stack_size, arg_heap_block_size>::const_iterator i;
|
||||
|
||||
if( escape )
|
||||
{
|
||||
/*
|
||||
* warning: char* (utf-8) string will not be correctly handled here
|
||||
*/
|
||||
for(i=arg.begin() ; i != arg.end() ; ++i)
|
||||
ETextPutChar(*i);
|
||||
}
|
||||
else
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(arg);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue