/* * This file is a part of Winix * and is not publicly distributed * * Copyright (c) 2010-2012, Tomasz Sowa * All rights reserved. * */ #ifndef headerfile_winix_templates_htmltextstream #define headerfile_winix_templates_htmltextstream #include #include "core/textstream.h" /* HtmlTextStream is used as a buffer for creating a html page By default all operators<< escape its string arguments. If you don't want to escape an argument you should use a helper function R() (raw argument) note: you have to define the function yourself, we do not provide it because such a short name would make a mess in namespaces sample: create a helper function R as follows: template HtmlTextStream::RawText R(const RawType & par) { return HtmlTextStream::RawText(par); } now you can use HtmlTextStream in an easy way: HtmlTextStream page; std::string key = "some string"; page << key << R("

html goes here

"); only html tags "" and "" will be correctly escaped currently following characters are escaped: < -> < > -> > & ->   */ class HtmlTextStream : public TextStream { public: /* a helper struct to select a proper operator<< (for non-escaping versions of these operators) */ template struct RawText { const RawType & par; RawText(const RawText & p) : par(p.par) {} RawText(const RawType & p) : par(p) {} }; /* without escaping */ HtmlTextStream & PutText(const char *); HtmlTextStream & PutText(const char *, size_t len); HtmlTextStream & PutText(const std::string *); HtmlTextStream & PutText(const std::string &); HtmlTextStream & PutText(const wchar_t * str); HtmlTextStream & PutText(const wchar_t * str, size_t len); HtmlTextStream & PutText(const std::wstring * str); HtmlTextStream & PutText(const std::wstring & str); /* we need this template operator for such calling: HtmlTextStream_object << R("some string"); "some string" is actually a table (not a pointer) */ template HtmlTextStream & operator<<(const RawText & raw) { return PutText(raw.par); } template HtmlTextStream & operator<<(const RawText & raw) { return PutText(raw.par); } HtmlTextStream & operator<<(const RawText & raw); HtmlTextStream & operator<<(const RawText & raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); HtmlTextStream & operator<<(RawText raw); // 'write' don't escapes too // with these methods you can write a zero character too HtmlTextStream & Write(const char * buf, size_t len); HtmlTextStream & Write(const wchar_t * buf, size_t len); // for compatibility with standard library (Ezc uses it) HtmlTextStream & write(const char * buf, size_t len); HtmlTextStream & write(const wchar_t * buf, size_t len); /* with escaping */ HtmlTextStream & ETextPutChar(char c); HtmlTextStream & ETextPutChar(wchar_t c); HtmlTextStream & EPutText(const char * str); HtmlTextStream & EPutText(const char * str, size_t len); HtmlTextStream & EPutText(const std::string * str); HtmlTextStream & EPutText(const std::string & str); HtmlTextStream & EPutText(const wchar_t * str); HtmlTextStream & EPutText(const wchar_t * str, size_t len); HtmlTextStream & EPutText(const std::wstring * str); HtmlTextStream & EPutText(const std::wstring & str); HtmlTextStream & operator<<(const char * str); HtmlTextStream & operator<<(const std::string * str); HtmlTextStream & operator<<(const std::string & str); HtmlTextStream & operator<<(const wchar_t * str); HtmlTextStream & operator<<(const std::wstring * str); HtmlTextStream & operator<<(const std::wstring & str); HtmlTextStream & operator<<(char); HtmlTextStream & operator<<(wchar_t); HtmlTextStream & operator<<(int); HtmlTextStream & operator<<(long); HtmlTextStream & operator<<(unsigned int); HtmlTextStream & operator<<(unsigned long); HtmlTextStream & operator<<(double); HtmlTextStream & operator<<(const void *); HtmlTextStream & operator<<(const tm & t); HtmlTextStream & operator<<(const PT::Space & space); HtmlTextStream & operator<<(const PT::Date & Date); private: TextStream space_stream; // for serializing spaces }; #endif