moved winix directories to winixdsubdirectory
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1028 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
607
winixd/templates/htmltextstream.cpp
Normal file
607
winixd/templates/htmltextstream.cpp
Normal file
@@ -0,0 +1,607 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010-2015, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "htmltextstream.h"
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
|
||||
|
||||
HtmlTextStream::HtmlTextStream()
|
||||
{
|
||||
escape = true;
|
||||
}
|
||||
|
||||
|
||||
void HtmlTextStream::Clear()
|
||||
{
|
||||
escape = true;
|
||||
TextStream<std::wstring>::Clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutChar(char c)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutChar(wchar_t c)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(c);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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>::Write(str, len);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const std::string * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const std::string & str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const wchar_t * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const std::wstring * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::PutText(const std::wstring & str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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::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)
|
||||
{
|
||||
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
|
||||
*/
|
||||
|
||||
|
||||
void HtmlTextStream::Escape(bool escape_characters)
|
||||
{
|
||||
escape = escape_characters;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::ETextPutChar(char c)
|
||||
{
|
||||
return ETextPutChar(static_cast<wchar_t>(c));
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::ETextPutChar(wchar_t c)
|
||||
{
|
||||
if( c == '<' )
|
||||
buffer += L"<";
|
||||
else
|
||||
if( c == '>' )
|
||||
buffer += L">";
|
||||
else
|
||||
if( c == '&' )
|
||||
buffer += L"&";
|
||||
else
|
||||
if( c == '\"' )
|
||||
buffer += L""";
|
||||
else
|
||||
if( c == '\'' )
|
||||
buffer += L"'"; // (it is "'" but IE8 has a problem with ')
|
||||
else
|
||||
if( c == 10 )
|
||||
buffer += L" ";
|
||||
else
|
||||
if( c == 13 )
|
||||
buffer += L" ";
|
||||
else
|
||||
if( c != 0 ) // !! CHECK ME may it should be changed to something like '�';
|
||||
buffer += c;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const char * str)
|
||||
{
|
||||
PT::UTF8ToWide(str, tmp_string);
|
||||
|
||||
for(size_t i=0 ; i<tmp_string.size() ; ++i)
|
||||
ETextPutChar(tmp_string[i]);
|
||||
|
||||
tmp_string.clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const char * str, size_t len)
|
||||
{
|
||||
PT::UTF8ToWide(str, len, tmp_string);
|
||||
|
||||
for(size_t i=0 ; i<tmp_string.size() ; ++i)
|
||||
ETextPutChar(tmp_string[i]);
|
||||
|
||||
tmp_string.clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const std::string * str)
|
||||
{
|
||||
return EPutText(*str);
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::EPutText(const std::string & str)
|
||||
{
|
||||
PT::UTF8ToWide(str, tmp_string);
|
||||
|
||||
for(size_t i=0 ; i<tmp_string.size() ; ++i)
|
||||
ETextPutChar(tmp_string[i]);
|
||||
|
||||
tmp_string.clear();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::string * str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::string & str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const wchar_t * str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::wstring * str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(const std::wstring & str)
|
||||
{
|
||||
if( escape )
|
||||
EPutText(str);
|
||||
else
|
||||
PutText(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(char v)
|
||||
{
|
||||
if( escape )
|
||||
ETextPutChar(v);
|
||||
else
|
||||
PutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
HtmlTextStream & HtmlTextStream::operator<<(wchar_t v)
|
||||
{
|
||||
if( escape )
|
||||
ETextPutChar(v);
|
||||
else
|
||||
PutChar(v);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user