/* * This file is a part of Winix * and is distributed under the 2-Clause BSD licence. * Author: Tomasz Sowa */ /* * Copyright (c) 2010-2014, 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; } /* without escaping */ HtmlTextStream & HtmlTextStream::PutChar(char c) { TextStream::operator<<(c); return *this; } HtmlTextStream & HtmlTextStream::PutChar(wchar_t c) { TextStream::operator<<(c); return *this; } HtmlTextStream & HtmlTextStream::PutText(const char * str) { TextStream::operator<<(str); return *this; } HtmlTextStream & HtmlTextStream::PutText(const char * str, size_t len) { TextStream::Write(str, len); return *this; } HtmlTextStream & HtmlTextStream::PutText(const std::string * str) { TextStream::operator<<(str); return *this; } HtmlTextStream & HtmlTextStream::PutText(const std::string & str) { TextStream::operator<<(str); return *this; } HtmlTextStream & HtmlTextStream::PutText(const wchar_t * str) { TextStream::operator<<(str); return *this; } HtmlTextStream & HtmlTextStream::PutText(const std::wstring * str) { TextStream::operator<<(str); return *this; } HtmlTextStream & HtmlTextStream::PutText(const std::wstring & str) { TextStream::operator<<(str); return *this; } HtmlTextStream & HtmlTextStream::operator<<(const RawText & raw) { return PutText(raw.par); } HtmlTextStream & HtmlTextStream::operator<<(const RawText & raw) { return PutText(raw.par); } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { return PutText(raw.par); } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { return PutText(raw.par); } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { return PutText(raw.par); } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { return PutText(raw.par); } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { TextStream::operator<<(raw.par); return *this; } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { TextStream::operator<<(raw.par); return *this; } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { TextStream::operator<<(raw.par); return *this; } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { TextStream::operator<<(raw.par); return *this; } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { TextStream::operator<<(raw.par); return *this; } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { TextStream::operator<<(raw.par); return *this; } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { TextStream::operator<<(raw.par); return *this; } HtmlTextStream & HtmlTextStream::operator<<(RawText raw) { TextStream::operator<<(raw.par); return *this; } 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) { TextStream::Write(buf, len); return *this; } HtmlTextStream & HtmlTextStream::Write(const wchar_t * buf, size_t len) { TextStream::Write(buf, len); return *this; } HtmlTextStream & HtmlTextStream::write(const char * buf, size_t len) { TextStream::write(buf, len); return *this; } HtmlTextStream & HtmlTextStream::write(const wchar_t * buf, size_t len) { TextStream::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(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 ; ic_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::operator<<(v); return *this; } HtmlTextStream & HtmlTextStream::operator<<(long v) { TextStream::operator<<(v); return *this; } HtmlTextStream & HtmlTextStream::operator<<(unsigned int v) { TextStream::operator<<(v); return *this; } HtmlTextStream & HtmlTextStream::operator<<(unsigned long v) { TextStream::operator<<(v); return *this; } HtmlTextStream & HtmlTextStream::operator<<(double v) { TextStream::operator<<(v); return *this; } HtmlTextStream & HtmlTextStream::operator<<(const void * v) { TextStream::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::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::operator<<(date); } return *this; } } // namespace Winix