winix/templates/htmltextstream.cpp

433 lines
6.5 KiB
C++
Raw Normal View History

added: uptime winix function prints how many sessions there are changed: functions for text/numbers conversions int Toi(const std::string & str, int base = 10); int Toi(const std::wstring & str, int base = 10); int Toi(const char * str, int base = 10); int Toi(const wchar_t * str, int base = 10); long Tol(const std::string & str, int base = 10); long Tol(const std::wstring & str, int base = 10); long Tol(const char * str, int base = 10); long Tol(const wchar_t * str, int base = 10); template<class CharType> bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10); template<class CharType> bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10); template<class CharType> bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10); template<class CharType> bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10); const wchar_t * Toa(unsigned int value, int base = 10); const wchar_t * Toa(unsigned long value, int base = 10); const wchar_t * Toa(int value, int base = 10); const wchar_t * Toa(long value, int base = 10); void Toa(int value, std::string & res, int base = 10, bool clear = true); void Toa(long value, std::string & res, int base = 10, bool clear = true); void Toa(int value, std::wstring & res, int base = 10, bool clear = true); void Toa(long value, std::wstring & res, int base = 10, bool clear = true); added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates) this is a special stream for automatically escaping html tags git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2012, Tomasz Sowa
added: uptime winix function prints how many sessions there are changed: functions for text/numbers conversions int Toi(const std::string & str, int base = 10); int Toi(const std::wstring & str, int base = 10); int Toi(const char * str, int base = 10); int Toi(const wchar_t * str, int base = 10); long Tol(const std::string & str, int base = 10); long Tol(const std::wstring & str, int base = 10); long Tol(const char * str, int base = 10); long Tol(const wchar_t * str, int base = 10); template<class CharType> bool Toa(unsigned long value, CharType * buffer, size_t buf_len, int base = 10); template<class CharType> bool Toa(long value, CharType * buffer, size_t buf_len, int base = 10); template<class CharType> bool Toa(unsigned int value, CharType * buffer, size_t buf_len, int base = 10); template<class CharType> bool Toa(int value, CharType * buffer, size_t buf_len, int base = 10); const wchar_t * Toa(unsigned int value, int base = 10); const wchar_t * Toa(unsigned long value, int base = 10); const wchar_t * Toa(int value, int base = 10); const wchar_t * Toa(long value, int base = 10); void Toa(int value, std::string & res, int base = 10, bool clear = true); void Toa(long value, std::string & res, int base = 10, bool clear = true); void Toa(int value, std::wstring & res, int base = 10, bool clear = true); void Toa(long value, std::wstring & res, int base = 10, bool clear = true); added: HtmlTextStream class (files htmltextstream.cpp htmltextstream.h in templates) this is a special stream for automatically escaping html tags git-svn-id: svn://ttmath.org/publicrep/winix/trunk@682 e52654a7-88a9-db11-a3e9-0013d4bc506e
2010-11-25 02:34:46 +01:00
* 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;
}