added: a new way: HEX format to saving/reading from PostgreSQL bytea columns
added: to Request: // binary page BinaryPage binary_page; // a compressed page ready to send to the client BinaryPage compressed_page; // if true then either page or ajaxpage will be sent to the client // if false then binary_page is sent // default: true bool use_text_page; BinaryPage is defined as (in requesttypes.h): typedef PT::TextStreamBase<char, 1, 4096> BinaryPage; added: to Compress: now it can gets BinaryPage as arguments (input, output) changed: winix version to: 0.5.0 added: in templates: TexTextStream class for taking input to the TeX typesetting system git-svn-id: svn://ttmath.org/publicrep/winix/trunk@884 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -967,6 +967,20 @@ templates.o: ../functions/subject.h ../functions/template.h
|
||||
templates.o: ../functions/tinymce.h ../functions/uname.h
|
||||
templates.o: ../functions/upload.h ../functions/uptime.h ../functions/who.h
|
||||
templates.o: ../functions/vim.h ../templates/templates.h
|
||||
textextstream.o: textextstream.h ../core/textstream.h misc.h localefilter.h
|
||||
textextstream.o: locale.h ../../pikotools/space/spaceparser.h
|
||||
textextstream.o: ../../pikotools/space/space.h
|
||||
textextstream.o: ../../pikotools/textstream/types.h
|
||||
textextstream.o: ../../pikotools/textstream/textstream.h
|
||||
textextstream.o: ../../pikotools/space/space.h ../../pikotools/date/date.h
|
||||
textextstream.o: ../../pikotools/convert/convert.h
|
||||
textextstream.o: ../../pikotools/convert/inttostr.h
|
||||
textextstream.o: ../../pikotools/membuffer/membuffer.h
|
||||
textextstream.o: ../../pikotools/textstream/types.h ../../ezc/src/ezc.h
|
||||
textextstream.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
|
||||
textextstream.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h
|
||||
textextstream.o: ../../ezc/src/functions.h ../../ezc/src/stringconv.h
|
||||
textextstream.o: ../../pikotools/utf8/utf8.h htmltextstream.h
|
||||
upload.o: ../core/request.h templates.h ../../ezc/src/ezc.h
|
||||
upload.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
|
||||
upload.o: ../../ezc/src/item.h ../../ezc/src/funinfo.h
|
||||
|
@@ -1 +1 @@
|
||||
o = adduser.o changepatterns.o config.o dir.o doc.o env.o filters.o htmltextstream.o indexpatterns.o insert.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o patterncacher.o patterns.o priv.o pw.o rebus.o slog.o stat.o sys.o template.o templates.o upload.o uptime.o user.o who.o winix.o
|
||||
o = adduser.o changepatterns.o config.o dir.o doc.o env.o filters.o htmltextstream.o indexpatterns.o insert.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o patterncacher.o patterns.o priv.o pw.o rebus.o slog.o stat.o sys.o template.o templates.o textextstream.o upload.o uptime.o user.o who.o winix.o
|
||||
|
456
templates/textextstream.cpp
Executable file
456
templates/textextstream.cpp
Executable file
@@ -0,0 +1,456 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "textextstream.h"
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream::TexTextStream()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const char * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const char * str, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::string * str)
|
||||
{
|
||||
return PutText(str->c_str());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::string & str)
|
||||
{
|
||||
return PutText(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const wchar_t * str)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::wstring * str)
|
||||
{
|
||||
return PutText(str->c_str());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::PutText(const std::wstring & str)
|
||||
{
|
||||
return PutText(str.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const RawText<const char*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const RawText<const wchar_t*> & raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<const std::string*> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<const std::wstring*> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<std::string> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<std::wstring> raw)
|
||||
{
|
||||
return PutText(raw.par);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<char> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<wchar_t> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<int> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<long> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<unsigned int> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<unsigned long> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<double> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(RawText<void*> raw)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(raw.par);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::Write(const char * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TexTextStream & TexTextStream::Write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::Write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::write(const char * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
TexTextStream & TexTextStream::write(const wchar_t * buf, size_t len)
|
||||
{
|
||||
TextStream<std::wstring>::write(buf, len);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
with escaping
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::ETextPutChar(char c)
|
||||
{
|
||||
return ETextPutChar(static_cast<wchar_t>(c));
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::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"$\\backslash$";
|
||||
else
|
||||
if( c == '{' )
|
||||
buffer += L"$\\{$";
|
||||
else
|
||||
if( c == '}' )
|
||||
buffer += L"$\\}$";
|
||||
else
|
||||
if( c == '^' )
|
||||
buffer += L""; // !! IMPROVE ME add \char with specific code
|
||||
else
|
||||
if( c == '_' )
|
||||
buffer += L"\\_";
|
||||
else
|
||||
if( c == '~' )
|
||||
buffer += L""; // !! IMPROVE ME add \char with specific code
|
||||
else
|
||||
if( c == '-' )
|
||||
buffer += L"{-}";
|
||||
else
|
||||
if( c != 0 )
|
||||
buffer += c;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const char * str)
|
||||
{
|
||||
for( ; *str ; ++str )
|
||||
ETextPutChar(*str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const char * str, size_t len)
|
||||
{
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
ETextPutChar(str[i]);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::string * str)
|
||||
{
|
||||
return EPutText(str->c_str(), str->size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::string & str)
|
||||
{
|
||||
return EPutText(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const wchar_t * str)
|
||||
{
|
||||
for( ; *str ; ++str )
|
||||
ETextPutChar(*str);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const wchar_t * str, size_t len)
|
||||
{
|
||||
for(size_t i=0 ; i<len ; ++i)
|
||||
ETextPutChar(str[i]);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::wstring * str)
|
||||
{
|
||||
return EPutText(str->c_str(), str->size());
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::EPutText(const std::wstring & str)
|
||||
{
|
||||
return EPutText(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const char * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::string * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::string & str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const wchar_t * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::wstring * str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const std::wstring & str)
|
||||
{
|
||||
return EPutText(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(char v)
|
||||
{
|
||||
ETextPutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(wchar_t v)
|
||||
{
|
||||
ETextPutChar(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(int v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(long v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(unsigned int v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(unsigned long v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(double v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const void * v)
|
||||
{
|
||||
TextStream<std::wstring>::operator<<(v);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const PT::Space & space)
|
||||
{
|
||||
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();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
TexTextStream & TexTextStream::operator<<(const PT::Date & date)
|
||||
{
|
||||
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();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
163
templates/textextstream.h
Executable file
163
templates/textextstream.h
Executable file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is not publicly distributed
|
||||
*
|
||||
* Copyright (c) 2012, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef headerfile_winix_templates_textextstream
|
||||
#define headerfile_winix_templates_textextstream
|
||||
|
||||
#include <ctime>
|
||||
#include "core/textstream.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
TexTextStream 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<class RawType>
|
||||
TexTextStream::RawText<RawType> R(const RawType & par)
|
||||
{
|
||||
return TexTextStream::RawText<RawType>(par);
|
||||
}
|
||||
|
||||
now you can use TexTextStream in an easy way:
|
||||
TexTextStream page;
|
||||
std::string key = "some <b>string</b>";
|
||||
page << key << R("<h2>html goes here</h2>");
|
||||
|
||||
// !! UPDATE INFO this is TEX text
|
||||
only html tags "<b>" and "</b>" will be correctly escaped
|
||||
|
||||
currently following characters are escaped:
|
||||
< -> <
|
||||
> -> >
|
||||
& ->
|
||||
*/
|
||||
class TexTextStream : public TextStream<std::wstring>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
TexTextStream();
|
||||
|
||||
|
||||
/*
|
||||
a helper struct to select a proper operator<<
|
||||
(for non-escaping versions of these operators)
|
||||
*/
|
||||
template<class RawType>
|
||||
struct RawText
|
||||
{
|
||||
const RawType & par;
|
||||
|
||||
RawText(const RawText<RawType> & p) : par(p.par) {}
|
||||
RawText(const RawType & p) : par(p) {}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
without escaping
|
||||
*/
|
||||
|
||||
TexTextStream & PutText(const char *);
|
||||
TexTextStream & PutText(const char *, size_t len);
|
||||
TexTextStream & PutText(const std::string *);
|
||||
TexTextStream & PutText(const std::string &);
|
||||
TexTextStream & PutText(const wchar_t * str);
|
||||
TexTextStream & PutText(const wchar_t * str, size_t len);
|
||||
TexTextStream & PutText(const std::wstring * str);
|
||||
TexTextStream & 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<size_t str_size>
|
||||
TexTextStream & operator<<(const RawText<char [str_size]> & raw) { return PutText(raw.par); }
|
||||
|
||||
template<size_t str_size>
|
||||
TexTextStream & operator<<(const RawText<wchar_t [str_size]> & raw) { return PutText(raw.par); }
|
||||
|
||||
TexTextStream & operator<<(const RawText<const char*> & raw);
|
||||
TexTextStream & operator<<(const RawText<const wchar_t*> & raw);
|
||||
TexTextStream & operator<<(RawText<const std::string*> raw);
|
||||
TexTextStream & operator<<(RawText<const std::wstring*> raw);
|
||||
TexTextStream & operator<<(RawText<std::string> raw);
|
||||
TexTextStream & operator<<(RawText<std::wstring> raw);
|
||||
|
||||
TexTextStream & operator<<(RawText<char> raw);
|
||||
TexTextStream & operator<<(RawText<wchar_t> raw);
|
||||
TexTextStream & operator<<(RawText<int> raw);
|
||||
TexTextStream & operator<<(RawText<long> raw);
|
||||
TexTextStream & operator<<(RawText<unsigned int> raw);
|
||||
TexTextStream & operator<<(RawText<unsigned long> raw);
|
||||
TexTextStream & operator<<(RawText<double> raw);
|
||||
TexTextStream & operator<<(RawText<void*> raw);
|
||||
|
||||
// 'write' don't escapes too
|
||||
// with these methods you can write a zero character too
|
||||
TexTextStream & Write(const char * buf, size_t len);
|
||||
TexTextStream & Write(const wchar_t * buf, size_t len);
|
||||
// for compatibility with standard library (Ezc uses it)
|
||||
TexTextStream & write(const char * buf, size_t len);
|
||||
TexTextStream & write(const wchar_t * buf, size_t len);
|
||||
|
||||
|
||||
/*
|
||||
with escaping
|
||||
*/
|
||||
|
||||
TexTextStream & ETextPutChar(char c);
|
||||
TexTextStream & ETextPutChar(wchar_t c);
|
||||
|
||||
TexTextStream & EPutText(const char * str);
|
||||
TexTextStream & EPutText(const char * str, size_t len);
|
||||
TexTextStream & EPutText(const std::string * str);
|
||||
TexTextStream & EPutText(const std::string & str);
|
||||
TexTextStream & EPutText(const wchar_t * str);
|
||||
TexTextStream & EPutText(const wchar_t * str, size_t len);
|
||||
TexTextStream & EPutText(const std::wstring * str);
|
||||
TexTextStream & EPutText(const std::wstring & str);
|
||||
|
||||
|
||||
TexTextStream & operator<<(const char * str);
|
||||
TexTextStream & operator<<(const std::string * str);
|
||||
TexTextStream & operator<<(const std::string & str);
|
||||
TexTextStream & operator<<(const wchar_t * str);
|
||||
TexTextStream & operator<<(const std::wstring * str);
|
||||
TexTextStream & operator<<(const std::wstring & str);
|
||||
TexTextStream & operator<<(char);
|
||||
TexTextStream & operator<<(wchar_t);
|
||||
TexTextStream & operator<<(int);
|
||||
TexTextStream & operator<<(long);
|
||||
TexTextStream & operator<<(unsigned int);
|
||||
TexTextStream & operator<<(unsigned long);
|
||||
TexTextStream & operator<<(double);
|
||||
TexTextStream & operator<<(const void *);
|
||||
TexTextStream & operator<<(const PT::Space & space);
|
||||
TexTextStream & operator<<(const PT::Date & Date);
|
||||
|
||||
private:
|
||||
|
||||
TextStream<std::wstring> tmp_stream;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user