winix/templates/htmltextstream.cpp

433 lines
6.5 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2012, Tomasz Sowa
* All rights reserved.
*
*/
#include "htmltextstream.h"
/*
without escaping
*/
HtmlTextStream & HtmlTextStream::PutText(const char * str)
{
TextStream<std::wstring>::operator<<(str);
return *this;
}
HtmlTextStream & HtmlTextStream::PutText(const char * str, size_t len)
{
TextStream<std::wstring>::operator<<(str);
return *this;
}
HtmlTextStream & HtmlTextStream::PutText(const std::string * str)
{
return PutText(str->c_str());
}
HtmlTextStream & HtmlTextStream::PutText(const std::string & str)
{
return PutText(str.c_str());
}
HtmlTextStream & HtmlTextStream::PutText(const wchar_t * str)
{
TextStream<std::wstring>::operator<<(str);
return *this;
}
HtmlTextStream & HtmlTextStream::PutText(const std::wstring * str)
{
return PutText(str->c_str());
}
HtmlTextStream & HtmlTextStream::PutText(const std::wstring & str)
{
return PutText(str.c_str());
}
HtmlTextStream & HtmlTextStream::operator<<(const RawText<const char*> & raw)
{
return PutText(raw.par);
}
HtmlTextStream & HtmlTextStream::operator<<(const RawText<const wchar_t*> & raw)
{
return PutText(raw.par);
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<const std::string*> raw)
{
return PutText(raw.par);
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<const std::wstring*> raw)
{
return PutText(raw.par);
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<std::string> raw)
{
return PutText(raw.par);
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<std::wstring> raw)
{
return PutText(raw.par);
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<char> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<wchar_t> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<int> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<long> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<unsigned int> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<unsigned long> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<double> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(RawText<void*> raw)
{
TextStream<std::wstring>::operator<<(raw.par);
return *this;
}
HtmlTextStream & HtmlTextStream::Write(const char * buf, size_t len)
{
TextStream<std::wstring>::Write(buf, len);
return *this;
}
HtmlTextStream & HtmlTextStream::Write(const wchar_t * buf, size_t len)
{
TextStream<std::wstring>::Write(buf, len);
return *this;
}
HtmlTextStream & HtmlTextStream::write(const char * buf, size_t len)
{
TextStream<std::wstring>::write(buf, len);
return *this;
}
HtmlTextStream & HtmlTextStream::write(const wchar_t * buf, size_t len)
{
TextStream<std::wstring>::write(buf, len);
return *this;
}
/*
with escaping
*/
HtmlTextStream & HtmlTextStream::ETextPutChar(char c)
{
return ETextPutChar(static_cast<wchar_t>(c));
}
HtmlTextStream & HtmlTextStream::ETextPutChar(wchar_t c)
{
if( c == '<' )
buffer += L"&lt;";
else
if( c == '>' )
buffer += L"&gt;";
else
if( c == '&' )
buffer += L"&amp;";
else
if( c != 0 )
buffer += c;
return *this;
}
HtmlTextStream & HtmlTextStream::EPutText(const char * str)
{
for( ; *str ; ++str )
ETextPutChar(*str);
return *this;
}
HtmlTextStream & HtmlTextStream::EPutText(const char * str, size_t len)
{
for(size_t i=0 ; i<len ; ++i)
ETextPutChar(str[i]);
return *this;
}
HtmlTextStream & HtmlTextStream::EPutText(const std::string * str)
{
return EPutText(str->c_str(), str->size());
}
HtmlTextStream & HtmlTextStream::EPutText(const std::string & str)
{
return EPutText(str.c_str(), str.size());
}
HtmlTextStream & HtmlTextStream::EPutText(const wchar_t * str)
{
for( ; *str ; ++str )
ETextPutChar(*str);
return *this;
}
HtmlTextStream & HtmlTextStream::EPutText(const wchar_t * str, size_t len)
{
for(size_t i=0 ; i<len ; ++i)
ETextPutChar(str[i]);
return *this;
}
HtmlTextStream & HtmlTextStream::EPutText(const std::wstring * str)
{
return EPutText(str->c_str(), str->size());
}
HtmlTextStream & HtmlTextStream::EPutText(const std::wstring & str)
{
return EPutText(str.c_str(), str.size());
}
HtmlTextStream & HtmlTextStream::operator<<(const char * str)
{
return EPutText(str);
}
HtmlTextStream & HtmlTextStream::operator<<(const std::string * str)
{
return EPutText(str);
}
HtmlTextStream & HtmlTextStream::operator<<(const std::string & str)
{
return EPutText(str);
}
HtmlTextStream & HtmlTextStream::operator<<(const wchar_t * str)
{
return EPutText(str);
}
HtmlTextStream & HtmlTextStream::operator<<(const std::wstring * str)
{
return EPutText(str);
}
HtmlTextStream & HtmlTextStream::operator<<(const std::wstring & str)
{
return EPutText(str);
}
HtmlTextStream & HtmlTextStream::operator<<(char v)
{
ETextPutChar(v);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(wchar_t v)
{
ETextPutChar(v);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(int v)
{
TextStream<std::wstring>::operator<<(v);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(long v)
{
TextStream<std::wstring>::operator<<(v);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(unsigned int v)
{
TextStream<std::wstring>::operator<<(v);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(unsigned long v)
{
TextStream<std::wstring>::operator<<(v);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(double v)
{
TextStream<std::wstring>::operator<<(v);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(const void * v)
{
TextStream<std::wstring>::operator<<(v);
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(const tm & t)
{
buffer += DateToStr(t); // from core/misc
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(const PT::Space & space)
{
space_stream.Clear();
// !! IMPROVE ME
// we can calculate how many memory is needed beforehand
space.Serialize(space_stream, true, false);
operator<<(space_stream.Str());
space_stream.Clear();
return *this;
}
HtmlTextStream & HtmlTextStream::operator<<(const PT::Date & date)
{
date.Serialize(*this);
return *this;
}