diff --git a/core/request.cpp b/core/request.cpp index e5f4276..fafdefb 100644 --- a/core/request.cpp +++ b/core/request.cpp @@ -71,12 +71,16 @@ size_t len = 16; if( len < 1 || len > 64 ) len = 16; - out_streams.resize(len); - use_html_filter.resize(len); + 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 raw) } +HtmlTextStream & HtmlTextStream::operator<<(RawText raw) +{ + TextStream::operator<<(raw.par); + return *this; +} + + +HtmlTextStream & HtmlTextStream::operator<<(RawText raw) +{ + TextStream::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) { - ETextPutChar(v); + if( escape ) + ETextPutChar(v); + else + PutChar(v); return *this; } @@ -428,7 +482,10 @@ return *this; HtmlTextStream & HtmlTextStream::operator<<(wchar_t v) { - ETextPutChar(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::operator<<(v); return *this; @@ -485,12 +547,23 @@ return *this; HtmlTextStream & HtmlTextStream::operator<<(const PT::Space & space) { - 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(); + 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::operator<<(space); + } return *this; } @@ -498,12 +571,23 @@ return *this; HtmlTextStream & HtmlTextStream::operator<<(const PT::Date & date) { - 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(); + 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::operator<<(date); + } return *this; } diff --git a/templates/htmltextstream.h b/templates/htmltextstream.h index bc8adfe..9de428e 100644 --- a/templates/htmltextstream.h +++ b/templates/htmltextstream.h @@ -137,6 +137,8 @@ public: HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); + HtmlTextStream & operator<<(RawText raw); + HtmlTextStream & operator<<(RawText raw); template HtmlTextStream & operator<<(RawText > 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 tmp_stream; + //TextStream tmp_stream; std::wstring tmp_string; + bool escape; }; @@ -213,8 +221,18 @@ HtmlTextStream & HtmlTextStream::operator<<(const PT::TextStreamBase::const_iterator i; - for(i=arg.begin() ; i != arg.end() ; ++i) - ETextPutChar(*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::operator<<(arg); + } return *this; }