diff --git a/Makefile.dep b/Makefile.dep index da6ea53..7399ac1 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -1 +1 @@ -winix.src.files = ./main/main.cpp ./db/dbconn.cpp ./db/db.cpp ./db/dbbase.h ./db/dbitemcolumns.cpp ./db/dbtextstream.cpp ./db/dbconn.h ./db/db.h ./db/dbitemcolumns.h ./db/dbitemquery.cpp ./db/dbtextstream.h ./db/dbitemquery.h ./db/dbbase.cpp ./core/synchro.h ./core/sessioncontainer.h ./core/cookieparser.h ./core/misc.cpp ./core/item.cpp ./core/error.h ./core/timezone.h ./core/compress.h ./core/crypt.cpp ./core/dirs.cpp ./core/slog.cpp ./core/config.cpp ./core/lastcontainer.cpp ./core/users.h ./core/httpsimpleparser.cpp ./core/threadmanager.h ./core/postparser.h ./core/pluginmsg.h ./core/acceptbaseparser.h ./core/loadavg.cpp ./core/job.h ./core/mountparser.cpp ./core/timezones.h ./core/sessionmanager.h ./core/groups.h ./core/system.cpp ./core/synchro.cpp ./core/rebus.h ./core/lock.cpp ./core/acceptencodingparser.h ./core/version.h ./core/compress.cpp ./core/ipbancontainer.cpp ./core/request.h ./core/plugindata.h ./core/plugin.cpp ./core/sessionparser.cpp ./core/bbcodeparser.h ./core/users.cpp ./core/mount.cpp ./core/basethread.cpp ./core/item.h ./core/slog.h ./core/acceptbaseparser.cpp ./core/lastcontainer.h ./core/httpsimpleparser.h ./core/timezones.cpp ./core/groups.cpp ./core/requesttypes.h ./core/system.h ./core/bbcodeparser.cpp ./core/lock.h ./core/ipbancontainer.h ./core/group.h ./core/plugin.h ./core/run.cpp ./core/textstream.h ./core/sessionparser.h ./core/basethread.h ./core/mount.h ./core/htmlfilter.cpp ./core/user.cpp ./core/app.cpp ./core/image.cpp ./core/ugcontainer.h ./core/postmultiparser.h ./core/logmanipulators.h ./core/sessioncontainer.cpp ./core/dircontainer.h ./core/log.h ./core/session.h ./core/timezone.cpp ./core/mounts.h ./core/ipban.h ./core/cur.h ./core/misc.h ./core/threadmanager.cpp ./core/dirs.h ./core/crypt.h ./core/run.h ./core/config.h ./core/job.cpp ./core/postmultiparser.cpp ./core/sessionmanager.cpp ./core/htmlfilter.h ./core/rebus.cpp ./core/dircontainer.cpp ./core/log.cpp ./core/user.h ./core/loadavg.h ./core/session.cpp ./core/mountparser.h ./core/mounts.cpp ./core/app.h ./core/image.h ./core/plugindata.cpp ./core/request.cpp ./core/winix_const.h ./functions/upload.cpp ./functions/priv.h ./functions/env.cpp ./functions/default.h ./functions/node.h ./functions/specialdefault.h ./functions/timezone.cpp ./functions/pw.h ./functions/adduser.h ./functions/chmod.h ./functions/imgcrop.cpp ./functions/vim.h ./functions/account.h ./functions/mount.cpp ./functions/uptime.cpp ./functions/ckeditor.cpp ./functions/mkdir.cpp ./functions/reload.cpp ./functions/functionparser.h ./functions/logout.cpp ./functions/rmuser.cpp ./functions/rm.cpp ./functions/chown.h ./functions/nicedit.h ./functions/mv.h ./functions/node.cpp ./functions/specialdefault.cpp ./functions/adduser.cpp ./functions/upload.h ./functions/vim.cpp ./functions/env.h ./functions/timezone.h ./functions/who.h ./functions/cp.cpp ./functions/run.cpp ./functions/locale.h ./functions/imgcrop.h ./functions/passwd.h ./functions/mount.h ./functions/privchanger.cpp ./functions/functions.cpp ./functions/last.h ./functions/ckeditor.h ./functions/mkdir.h ./functions/reload.h ./functions/cat.h ./functions/download.h ./functions/ln.h ./functions/nicedit.cpp ./functions/functionbase.cpp ./functions/man.h ./functions/rm.h ./functions/meta.cpp ./functions/emacs.cpp ./functions/sort.h ./functions/who.cpp ./functions/ipban.h ./functions/locale.cpp ./functions/passwd.cpp ./functions/last.cpp ./functions/subject.h ./functions/download.cpp ./functions/cp.h ./functions/cat.cpp ./functions/login.cpp ./functions/tinymce.cpp ./functions/ln.cpp ./functions/run.h ./functions/uname.h ./functions/man.cpp ./functions/functions.h ./functions/privchanger.h ./functions/ls.cpp ./functions/template.h ./functions/stat.h ./functions/priv.cpp ./functions/default.cpp ./functions/functionbase.h ./functions/pw.cpp ./functions/sort.cpp ./functions/ipban.cpp ./functions/chmod.cpp ./functions/meta.h ./functions/account.cpp ./functions/emacs.h ./functions/subject.cpp ./functions/functionparser.cpp ./functions/uname.cpp ./functions/uptime.h ./functions/template.cpp ./functions/stat.cpp ./functions/tinymce.h ./functions/login.h ./functions/chown.cpp ./functions/logout.h ./functions/mv.cpp ./functions/rmuser.h ./functions/ls.h ./notify/notifypool.h ./notify/templatesnotify.cpp ./notify/notify.cpp ./notify/templatesnotify.h ./notify/notify.h ./notify/notifythread.cpp ./notify/notifypool.cpp ./notify/notifythread.h ./templates/who.cpp ./templates/item.cpp ./templates/mount.cpp ./templates/templates.h ./templates/locale.h ./templates/slog.cpp ./templates/doc.cpp ./templates/localefilter.cpp ./templates/config.cpp ./templates/patterns.h ./templates/miscspace.cpp ./templates/filters.cpp ./templates/login.cpp ./templates/man.cpp ./templates/changepatterns.h ./templates/stat.cpp ./templates/template.cpp ./templates/dir.cpp ./templates/user.cpp ./templates/rebus.cpp ./templates/patterncacher.cpp ./templates/upload.cpp ./templates/textextstream.h ./templates/adduser.cpp ./templates/ipban.cpp ./templates/htmltextstream.h ./templates/indexpatterns.h ./templates/templates.cpp ./templates/winix.cpp ./templates/locale.cpp ./templates/misc.h ./templates/patterns.cpp ./templates/passwd.cpp ./templates/last.cpp ./templates/uptime.cpp ./templates/insert.cpp ./templates/changepatterns.cpp ./templates/localefilter.h ./templates/miscspace.h ./templates/ls.cpp ./templates/sys.cpp ./templates/priv.cpp ./templates/textextstream.cpp ./templates/htmltextstream.cpp ./templates/env.cpp ./templates/indexpatterns.cpp ./templates/patterncacher.h ./templates/misc.cpp ./plugins/group/init.cpp ./plugins/group/groups.h ./plugins/group/groupinfo.cpp ./plugins/group/groupinfo.h ./plugins/group/templates.cpp ./plugins/group/groups.cpp ./plugins/stats/statssession.h ./plugins/stats/bot.h ./plugins/stats/stats.cpp ./plugins/stats/templates.cpp ./plugins/stats/init.cpp ./plugins/stats/stats.h ./plugins/stats/templates.h ./plugins/stats/bot.cpp ./plugins/gallery/galleryinfo.cpp ./plugins/gallery/templates.cpp ./plugins/gallery/gallery.cpp ./plugins/gallery/galleryinfo.h ./plugins/gallery/init.cpp ./plugins/gallery/gallery.h ./plugins/export/init.cpp ./plugins/export/export.h ./plugins/export/exportthread.cpp ./plugins/export/message.h ./plugins/export/edb.cpp ./plugins/export/funexport.cpp ./plugins/export/exportinfo.cpp ./plugins/export/exportthread.h ./plugins/export/edb.h ./plugins/export/funexport.h ./plugins/export/exportinfo.h ./plugins/ticket/funticket.h ./plugins/ticket/init.cpp ./plugins/ticket/ticketinfo.h ./plugins/ticket/showtickets.cpp ./plugins/ticket/createticket.cpp ./plugins/ticket/tdb.cpp ./plugins/ticket/pluginmsg.h ./plugins/ticket/createticket.h ./plugins/ticket/showtickets.h ./plugins/ticket/sessiondata.cpp ./plugins/ticket/tdb.h ./plugins/ticket/sessiondata.h ./plugins/ticket/ticket.h ./plugins/ticket/editticket.cpp ./plugins/ticket/funticket.cpp ./plugins/ticket/templates.cpp ./plugins/ticket/editticket.h ./plugins/ticket/ticketinfo.cpp ./plugins/menu/cache.cpp ./plugins/menu/init.cpp ./plugins/menu/cache.h ./plugins/menu/templates.cpp ./plugins/thread/funthread.cpp ./plugins/thread/threadinfo.cpp ./plugins/thread/funthread.h ./plugins/thread/threadinfo.h ./plugins/thread/createthread.cpp ./plugins/thread/reply.cpp ./plugins/thread/showthreads.cpp ./plugins/thread/templates.cpp ./plugins/thread/createthread.h ./plugins/thread/reply.h ./plugins/thread/showthreads.h ./plugins/thread/init.cpp ./plugins/thread/templates.h ./plugins/thread/tdb.cpp ./plugins/thread/pluginmsg.h ./plugins/thread/thread.h ./plugins/thread/tdb.h ../ezc/src/funinfo.h ../ezc/src/patternparser.cpp ../ezc/src/generator.h ../ezc/src/functions.h ../ezc/src/pattern.cpp ../ezc/src/item.cpp ../ezc/src/patternparser.h ../ezc/src/pattern.h ../ezc/src/item.h ../ezc/src/ezc.h ../ezc/src/cache.cpp ../ezc/src/cache.h ../ezc/src/blocks.h ../ezc/src/blocks.cpp ../tito/src/crypto.cpp ../tito/src/misc.h ../tito/src/base64.cpp ../tito/src/crypto.h ../tito/src/aes.cpp ../tito/src/base64.h ../tito/src/misc.cpp ../tito/src/aes.h ../pikotools/mainparser/sample/sample.cpp ../pikotools/mainparser/mainparser.cpp ../pikotools/mainparser/mainparser.h ../pikotools/space/space.h ../pikotools/space/spaceparser.cpp ../pikotools/space/space.cpp ../pikotools/space/spaceparser.h ../pikotools/space/jsontospaceparser.cpp ../pikotools/space/spacetojson.cpp ../pikotools/space/jsontospaceparser.h ../pikotools/space/spacetojson.h ../pikotools/date/date.h ../pikotools/date/date.cpp ../pikotools/membuffer/membuffer.h ../pikotools/utf8/utf8.cpp ../pikotools/utf8/utf8.h ../pikotools/textstream/textstream.h ../pikotools/textstream/types.h ../pikotools/convert/convert.h ../pikotools/convert/inttostr.h \ No newline at end of file +winix.src.files = ./main/main.cpp ./db/dbconn.cpp ./db/db.cpp ./db/dbbase.h ./db/dbitemcolumns.cpp ./db/dbtextstream.cpp ./db/dbconn.h ./db/db.h ./db/dbitemcolumns.h ./db/dbitemquery.cpp ./db/dbtextstream.h ./db/dbitemquery.h ./db/dbbase.cpp ./core/synchro.h ./core/sessioncontainer.h ./core/cookieparser.h ./core/misc.cpp ./core/item.cpp ./core/error.h ./core/timezone.h ./core/compress.h ./core/crypt.cpp ./core/dirs.cpp ./core/slog.cpp ./core/config.cpp ./core/lastcontainer.cpp ./core/users.h ./core/httpsimpleparser.cpp ./core/threadmanager.h ./core/postparser.h ./core/pluginmsg.h ./core/acceptbaseparser.h ./core/loadavg.cpp ./core/job.h ./core/mountparser.cpp ./core/timezones.h ./core/sessionmanager.h ./core/groups.h ./core/system.cpp ./core/synchro.cpp ./core/rebus.h ./core/lock.cpp ./core/acceptencodingparser.h ./core/version.h ./core/compress.cpp ./core/ipbancontainer.cpp ./core/request.h ./core/plugindata.h ./core/plugin.cpp ./core/sessionparser.cpp ./core/bbcodeparser.h ./core/users.cpp ./core/mount.cpp ./core/basethread.cpp ./core/item.h ./core/slog.h ./core/acceptbaseparser.cpp ./core/lastcontainer.h ./core/httpsimpleparser.h ./core/timezones.cpp ./core/groups.cpp ./core/requesttypes.h ./core/system.h ./core/bbcodeparser.cpp ./core/lock.h ./core/ipbancontainer.h ./core/group.h ./core/plugin.h ./core/run.cpp ./core/textstream.h ./core/sessionparser.h ./core/basethread.h ./core/mount.h ./core/htmlfilter.cpp ./core/user.cpp ./core/app.cpp ./core/image.cpp ./core/ugcontainer.h ./core/postmultiparser.h ./core/logmanipulators.h ./core/sessioncontainer.cpp ./core/dircontainer.h ./core/log.h ./core/session.h ./core/timezone.cpp ./core/mounts.h ./core/ipban.h ./core/cur.h ./core/misc.h ./core/threadmanager.cpp ./core/dirs.h ./core/crypt.h ./core/run.h ./core/config.h ./core/job.cpp ./core/postmultiparser.cpp ./core/sessionmanager.cpp ./core/htmlfilter.h ./core/rebus.cpp ./core/dircontainer.cpp ./core/log.cpp ./core/user.h ./core/loadavg.h ./core/session.cpp ./core/mountparser.h ./core/mounts.cpp ./core/app.h ./core/image.h ./core/plugindata.cpp ./core/request.cpp ./core/winix_const.h ./functions/upload.cpp ./functions/priv.h ./functions/env.cpp ./functions/default.h ./functions/node.h ./functions/specialdefault.h ./functions/timezone.cpp ./functions/pw.h ./functions/adduser.h ./functions/chmod.h ./functions/imgcrop.cpp ./functions/vim.h ./functions/account.h ./functions/mount.cpp ./functions/uptime.cpp ./functions/ckeditor.cpp ./functions/mkdir.cpp ./functions/reload.cpp ./functions/functionparser.h ./functions/logout.cpp ./functions/rmuser.cpp ./functions/rm.cpp ./functions/chown.h ./functions/nicedit.h ./functions/mv.h ./functions/node.cpp ./functions/specialdefault.cpp ./functions/adduser.cpp ./functions/upload.h ./functions/vim.cpp ./functions/env.h ./functions/timezone.h ./functions/who.h ./functions/cp.cpp ./functions/run.cpp ./functions/locale.h ./functions/imgcrop.h ./functions/passwd.h ./functions/mount.h ./functions/privchanger.cpp ./functions/functions.cpp ./functions/last.h ./functions/ckeditor.h ./functions/mkdir.h ./functions/reload.h ./functions/cat.h ./functions/download.h ./functions/ln.h ./functions/nicedit.cpp ./functions/functionbase.cpp ./functions/man.h ./functions/rm.h ./functions/meta.cpp ./functions/emacs.cpp ./functions/sort.h ./functions/who.cpp ./functions/ipban.h ./functions/locale.cpp ./functions/passwd.cpp ./functions/last.cpp ./functions/subject.h ./functions/download.cpp ./functions/cp.h ./functions/cat.cpp ./functions/login.cpp ./functions/tinymce.cpp ./functions/ln.cpp ./functions/run.h ./functions/uname.h ./functions/man.cpp ./functions/functions.h ./functions/privchanger.h ./functions/ls.cpp ./functions/template.h ./functions/stat.h ./functions/priv.cpp ./functions/default.cpp ./functions/functionbase.h ./functions/pw.cpp ./functions/sort.cpp ./functions/ipban.cpp ./functions/chmod.cpp ./functions/meta.h ./functions/account.cpp ./functions/emacs.h ./functions/subject.cpp ./functions/functionparser.cpp ./functions/uname.cpp ./functions/uptime.h ./functions/template.cpp ./functions/stat.cpp ./functions/tinymce.h ./functions/login.h ./functions/chown.cpp ./functions/logout.h ./functions/mv.cpp ./functions/rmuser.h ./functions/ls.h ./notify/notifypool.h ./notify/templatesnotify.cpp ./notify/notify.cpp ./notify/templatesnotify.h ./notify/notify.h ./notify/notifythread.cpp ./notify/notifypool.cpp ./notify/notifythread.h ./templates/who.cpp ./templates/item.cpp ./templates/mount.cpp ./templates/templates.h ./templates/locale.h ./templates/slog.cpp ./templates/doc.cpp ./templates/localefilter.cpp ./templates/config.cpp ./templates/patterns.h ./templates/miscspace.cpp ./templates/filters.cpp ./templates/login.cpp ./templates/man.cpp ./templates/changepatterns.h ./templates/stat.cpp ./templates/template.cpp ./templates/dir.cpp ./templates/user.cpp ./templates/rebus.cpp ./templates/patterncacher.cpp ./templates/upload.cpp ./templates/textextstream.h ./templates/adduser.cpp ./templates/ipban.cpp ./templates/htmltextstream.h ./templates/indexpatterns.h ./templates/templates.cpp ./templates/winix.cpp ./templates/locale.cpp ./templates/misc.h ./templates/patterns.cpp ./templates/passwd.cpp ./templates/last.cpp ./templates/uptime.cpp ./templates/insert.cpp ./templates/changepatterns.cpp ./templates/localefilter.h ./templates/miscspace.h ./templates/ls.cpp ./templates/sys.cpp ./templates/priv.cpp ./templates/textextstream.cpp ./templates/htmltextstream.cpp ./templates/env.cpp ./templates/indexpatterns.cpp ./templates/patterncacher.h ./templates/misc.cpp ./templates/generic.cpp ./plugins/group/init.cpp ./plugins/group/groups.h ./plugins/group/groupinfo.cpp ./plugins/group/groupinfo.h ./plugins/group/templates.cpp ./plugins/group/groups.cpp ./plugins/stats/statssession.h ./plugins/stats/bot.h ./plugins/stats/stats.cpp ./plugins/stats/templates.cpp ./plugins/stats/init.cpp ./plugins/stats/stats.h ./plugins/stats/templates.h ./plugins/stats/bot.cpp ./plugins/gallery/galleryinfo.cpp ./plugins/gallery/templates.cpp ./plugins/gallery/gallery.cpp ./plugins/gallery/galleryinfo.h ./plugins/gallery/init.cpp ./plugins/gallery/gallery.h ./plugins/export/init.cpp ./plugins/export/export.h ./plugins/export/exportthread.cpp ./plugins/export/message.h ./plugins/export/edb.cpp ./plugins/export/funexport.cpp ./plugins/export/exportinfo.cpp ./plugins/export/exportthread.h ./plugins/export/edb.h ./plugins/export/funexport.h ./plugins/export/exportinfo.h ./plugins/ticket/funticket.h ./plugins/ticket/init.cpp ./plugins/ticket/ticketinfo.h ./plugins/ticket/showtickets.cpp ./plugins/ticket/createticket.cpp ./plugins/ticket/tdb.cpp ./plugins/ticket/pluginmsg.h ./plugins/ticket/createticket.h ./plugins/ticket/showtickets.h ./plugins/ticket/sessiondata.cpp ./plugins/ticket/tdb.h ./plugins/ticket/sessiondata.h ./plugins/ticket/ticket.h ./plugins/ticket/editticket.cpp ./plugins/ticket/funticket.cpp ./plugins/ticket/templates.cpp ./plugins/ticket/editticket.h ./plugins/ticket/ticketinfo.cpp ./plugins/menu/cache.cpp ./plugins/menu/init.cpp ./plugins/menu/cache.h ./plugins/menu/templates.cpp ./plugins/thread/funthread.cpp ./plugins/thread/threadinfo.cpp ./plugins/thread/funthread.h ./plugins/thread/threadinfo.h ./plugins/thread/createthread.cpp ./plugins/thread/reply.cpp ./plugins/thread/showthreads.cpp ./plugins/thread/templates.cpp ./plugins/thread/createthread.h ./plugins/thread/reply.h ./plugins/thread/showthreads.h ./plugins/thread/init.cpp ./plugins/thread/templates.h ./plugins/thread/tdb.cpp ./plugins/thread/pluginmsg.h ./plugins/thread/thread.h ./plugins/thread/tdb.h ../ezc/src/funinfo.h ../ezc/src/patternparser.cpp ../ezc/src/generator.h ../ezc/src/functions.h ../ezc/src/pattern.cpp ../ezc/src/item.cpp ../ezc/src/patternparser.h ../ezc/src/pattern.h ../ezc/src/item.h ../ezc/src/ezc.h ../ezc/src/cache.cpp ../ezc/src/cache.h ../ezc/src/blocks.h ../ezc/src/blocks.cpp ../tito/src/crypto.cpp ../tito/src/misc.h ../tito/src/base64.cpp ../tito/src/crypto.h ../tito/src/aes.cpp ../tito/src/base64.h ../tito/src/misc.cpp ../tito/src/aes.h ../pikotools/mainparser/sample/sample.cpp ../pikotools/mainparser/mainparser.cpp ../pikotools/mainparser/mainparser.h ../pikotools/space/space.h ../pikotools/space/spaceparser.cpp ../pikotools/space/space.cpp ../pikotools/space/spaceparser.h ../pikotools/space/jsontospaceparser.cpp ../pikotools/space/spacetojson.cpp ../pikotools/space/jsontospaceparser.h ../pikotools/space/spacetojson.h ../pikotools/date/date.h ../pikotools/date/date.cpp ../pikotools/membuffer/membuffer.h ../pikotools/utf8/utf8.cpp ../pikotools/utf8/utf8.h ../pikotools/textstream/textstream.h ../pikotools/textstream/types.h ../pikotools/convert/convert.h ../pikotools/convert/inttostr.h \ No newline at end of file diff --git a/core/misc.cpp b/core/misc.cpp index 547e403..de1eff3 100644 --- a/core/misc.cpp +++ b/core/misc.cpp @@ -51,7 +51,7 @@ namespace Winix namespace misc_private { // white_chars table should be sorted - // we do not treat a new line character (10) as a white character + // we do not treat a new line character (10) as a white character here static const wchar_t white_chars[] = { 0x0009, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0, 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028, @@ -61,7 +61,16 @@ namespace misc_private } - +/* + * IMPROVE ME + * we ca add our own functions with treat_new_line_as_white flag + * and with a pointer pointing after the number + * + * Toi(const wchar_t * str, const wchar_t ** str_after, bool treat_new_line_as_white); + * Toi(const wchar_t * str, bool treat_new_line_as_white); + * Toi(const std::wstring & str, bool treat_new_line_as_white); + * + */ int Toi(const std::string & str, int base) { return Toi(str.c_str(), base); @@ -471,9 +480,9 @@ PT::WTextStream IPToStr(int ip) /* - we do not treat a new line character (10) as a white character + by default we do not treat a new line character (10) as a white character */ -bool IsWhite(wchar_t c) +bool IsWhite(wchar_t c, bool treat_new_line_as_white) { using misc_private::white_chars; @@ -481,6 +490,9 @@ using misc_private::white_chars; size_t o1 = 0; size_t o2 = len - 1; + if( c == 10 ) + return treat_new_line_as_white ? true : false; + if( c < white_chars[o1] || c > white_chars[o2] ) return false; @@ -513,13 +525,7 @@ bool IsWhite(const wchar_t * str, bool treat_new_line_as_white) { for( ; *str != 0 ; ++str ) { - if( *str == '\n' ) - { - if( !treat_new_line_as_white ) - return false; - } - else - if( !IsWhite(*str) ) + if( !IsWhite(*str, treat_new_line_as_white) ) return false; } @@ -538,6 +544,95 @@ bool IsWhite(const std::wstring & str, bool treat_new_line_as_white) +void TrimWhite(std::wstring & s, bool trim_new_line_too) +{ +size_t i; + + if( s.empty() ) + return; + + // looking for white characters at the end + for(i=s.size()-1 ; i>0 && IsWhite(s[i], trim_new_line_too) ; --i); + + if( i==0 && IsWhite(s[i], trim_new_line_too) ) + { + // the whole string has white characters + s.clear(); + return; + } + + // deleting white characters at the end + if( i != s.size() - 1 ) + s.erase(i+1, std::wstring::npos); + + // looking for white characters at the beginning + for(i=0 ; i0 && s[i]==c ; --i); + + if( i==0 && s[i]==c ) + { + // the whole string has the 'c' characters + s.clear(); + return; + } + + // deleting 'c' characters at the end + if( i != s.size() - 1 ) + s.erase(i+1, std::wstring::npos); +} + + + +void Trim(std::wstring & s, wchar_t c) +{ + if( s.empty() ) + return; + + TrimLast(s, c); + TrimFirst(s, c); +} bool IsLastSlash(const std::wstring & path) @@ -549,6 +644,97 @@ return path[path.size()-1] == '/'; } +bool IsInt(const wchar_t * str, bool treat_new_line_as_white, bool allow_negative_value) +{ +size_t digit = 0; + + str = SkipWhite(str, treat_new_line_as_white); + + if( allow_negative_value && *str == '-' ) + str += 1; + + while( *str>='0' && *str<='9' ) + { + digit += 1; + str += 1; + } + + if( digit == 0 ) + return false; + + str = SkipWhite(str, treat_new_line_as_white); + + if( *str != 0 ) + return false; + +return true; +} + +bool IsInt(const wchar_t * str, bool treat_new_line_as_white) +{ + return IsInt(str, treat_new_line_as_white, true); +} + + +bool IsInt(const std::wstring & str, bool treat_new_line_as_white) +{ + return IsInt(str.c_str(), treat_new_line_as_white); +} + + + +bool IsSize(const wchar_t * str, bool treat_new_line_as_white) +{ + return IsInt(str, treat_new_line_as_white, false); +} + + +bool IsSize(const std::wstring & str, bool treat_new_line_as_white) +{ + return IsSize(str.c_str(), treat_new_line_as_white); +} + + + +bool IsFloat(const wchar_t * str, bool treat_new_line_as_white) +{ +size_t digit = 0; +size_t comma = 0; + + str = SkipWhite(str, treat_new_line_as_white); + + if( *str == '-' ) + str += 1; + + while( (*str == ',' || *str == '.') || (*str>='0' && *str<='9') ) + { + if( *str == ',' || *str == '.' ) + comma += 1; + else + digit += 1; + + str += 1; + } + + if( comma > 1 || digit == 0 ) + return false; + + str = SkipWhite(str, treat_new_line_as_white); + + if( *str != 0 ) + return false; + +return true; +} + + +bool IsFloat(const std::wstring & str, bool treat_new_line_as_white) +{ + return IsFloat(str.c_str(), treat_new_line_as_white); +} + + + void Overwrite(std::string & str) { @@ -564,23 +750,6 @@ void Overwrite(std::wstring & str) -const char * SkipWhite(const char * s) -{ - while( IsWhite(*s) ) - ++s; - -return s; -} - - -const wchar_t * SkipWhite(const wchar_t * s) -{ - while( IsWhite(*s) ) - ++s; - -return s; -} - wchar_t ToSmall(wchar_t c) { diff --git a/core/misc.h b/core/misc.h index 3036764..b4a69b3 100644 --- a/core/misc.h +++ b/core/misc.h @@ -243,94 +243,70 @@ PT::WTextStream IPToStr(int ip); -bool IsWhite(wchar_t s); +bool IsWhite(wchar_t s, bool treat_new_line_as_white = false); bool IsWhite(const wchar_t * str, bool treat_new_line_as_white = false); bool IsWhite(const std::wstring & str, bool treat_new_line_as_white = false); + +void TrimWhite(std::wstring & s, bool trim_new_line_too = false); + +const wchar_t * SkipWhite(const wchar_t * s, bool treat_new_line_as_white = false); + + +void TrimFirst(std::wstring & s, wchar_t c); +void TrimLast(std::wstring & s, wchar_t c); +void Trim(std::wstring & s, wchar_t c); + + bool IsLastSlash(const std::wstring & path); -template -void TrimWhite(StringType & s) -{ -typename StringType::size_type i; - - if( s.empty() ) - return; - - // looking for white characters at the end - for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i); - - if( i==0 && IsWhite(s[i]) ) - { - // the whole string has white characters - s.clear(); - return; - } - - // deleting white characters at the end - if( i != s.size() - 1 ) - s.erase(i+1, StringType::npos); - - // looking for white characters at the beginning - for(i=0 ; i -void TrimFirst(StringType & s, wchar_t c) -{ -typename StringType::size_type i; - - if( s.empty() ) - return; - - // looking for the 'c' characters at the beginning - for(i=0 ; i -void TrimLast(StringType & s, wchar_t c) -{ -typename StringType::size_type i; - - if( s.empty() ) - return; - - // looking for the 'c' characters at the end - for(i=s.size()-1 ; i>0 && s[i]==c ; --i); - - if( i==0 && s[i]==c ) - { - // the whole string has the 'c' characters - s.clear(); - return; - } - - // deleting 'c' characters at the end - if( i != s.size() - 1 ) - s.erase(i+1, StringType::npos); -} - - - -template -void Trim(StringType & s, wchar_t c) -{ - if( s.empty() ) - return; - - TrimLast(s, c); - TrimFirst(s, c); -} - +/* + * returns true if str is a floating point number + * white strings at the beginning and at the end are ignored + * as a decimal comma can be a dot or a comma + * e.g. returns true for: + * " 10 " + * " -20.3 " + * " 30,5 " + * e.g. returns false for: + * "" + * "- 20.1" + * "20.1.2" + * "z" + */ +bool IsFloat(const wchar_t * str, bool treat_new_line_as_white = false); +bool IsFloat(const std::wstring & str, bool treat_new_line_as_white = false); void Overwrite(std::string & str); @@ -391,8 +367,7 @@ bool was_comma = false; wchar_t ToSmall(wchar_t c); void ToSmall(std::wstring & s); -const char * SkipWhite(const char * s); -const wchar_t * SkipWhite(const wchar_t * s); + diff --git a/core/version.h b/core/version.h index 7fc97ac..47400ad 100644 --- a/core/version.h +++ b/core/version.h @@ -42,7 +42,7 @@ namespace Winix #define WINIX_VER_MAJOR 0 #define WINIX_VER_MINOR 6 -#define WINIX_VER_REVISION 3 +#define WINIX_VER_REVISION 4 diff --git a/html/fun_locale.html b/html/fun_locale.html index b183884..c3e337a 100644 --- a/html/fun_locale.html +++ b/html/fun_locale.html @@ -18,7 +18,7 @@ [# add to styles] diff --git a/html/fun_pw.html b/html/fun_pw.html index 04722ad..eb68441 100644 --- a/html/fun_pw.html +++ b/html/fun_pw.html @@ -14,7 +14,7 @@ [for user_tab] - + [user_tab_index] [user_tab_name] [if user_tab_is_super_user]{pw_table_yes}[end] diff --git a/html/fun_sort.html b/html/fun_sort.html index 7c599e9..85898f0 100644 --- a/html/fun_sort.html +++ b/html/fun_sort.html @@ -36,7 +36,7 @@ [# is it correct? may give this 'if' only to /-/thumb param? ] [if item_tab_has_thumb][item_tab_subject][end] - [item_tab_url] [is-no item_tab_subject str ""]({sort_item_subject}: [item_tab_subject])[end] + [item_tab_url] [if not [cmp [item_tab_subject] [str ""]]]({sort_item_subject}: [item_tab_subject])[end] [end] diff --git a/html/fun_thread.html b/html/fun_thread.html index 74d9836..b5d9c90 100644 --- a/html/fun_thread.html +++ b/html/fun_thread.html @@ -23,7 +23,7 @@ [for thread_sort_tab] -
+
[if thread_sort_tab_can_write]\[{edit}\][end] [if thread_mount_arg_is "subject"][thread_sort_tab_subject][end] [if thread_mount_arg_is "info"][include "thread_sort_tab_info.html"][end] diff --git a/html/fun_ticket.html b/html/fun_ticket.html index d23797e..6f152ac 100644 --- a/html/fun_ticket.html +++ b/html/fun_ticket.html @@ -56,7 +56,7 @@ [for thread_sort_tab] -
+
[if thread_sort_tab_can_write]\[{edit}\][end] [if thread_mount_arg_is "subject"][thread_sort_tab_subject][end] [if thread_mount_arg_is "info"][include "thread_sort_tab_info.html"][end] diff --git a/html/fun_timezone.html b/html/fun_timezone.html index 8fed8e7..8a0f2f2 100644 --- a/html/fun_timezone.html +++ b/html/fun_timezone.html @@ -18,7 +18,7 @@ [# add to styles] diff --git a/html/item_tab_info.html b/html/item_tab_info.html index 4bf08d4..e4e1047 100644 --- a/html/item_tab_info.html +++ b/html/item_tab_info.html @@ -1,4 +1,4 @@ -

+

{added_by}: [item_tab_user], [item_tab_date_creation_nice][if-no item_tab_dates_equal], {last_modified}[if-one item_tab_users_different] {by}: [item_tab_modification_user],[else]:[end] diff --git a/html/thread_sort_tab_info.html b/html/thread_sort_tab_info.html index 1ecab64..2ed34ea 100644 --- a/html/thread_sort_tab_info.html +++ b/html/thread_sort_tab_info.html @@ -1,4 +1,4 @@ -

+

{added_by}: [thread_sort_tab_user], [thread_sort_tab_date_creation_nice][if-no thread_sort_tab_dates_equal], {last_modified}[if thread_sort_tab_users_different] {by}: [thread_sort_tab_modification_user],[else]:[end] diff --git a/templates/Makefile.dep b/templates/Makefile.dep index df8ba57..843b163 100644 --- a/templates/Makefile.dep +++ b/templates/Makefile.dep @@ -353,6 +353,57 @@ filters.o: ../../winix/core/sessioncontainer.h filters.o: ../../winix/core/ipbancontainer.h ../../winix/core/system.h filters.o: ../../winix/core/htmlfilter.h ../../winix/core/misc.h filters.o: ../../winix/core/winix_const.h +generic.o: templates.h ../../ezc/src/ezc.h ../../ezc/src/generator.h +generic.o: ../../ezc/src/blocks.h ../../ezc/src/item.h +generic.o: ../../ezc/src/funinfo.h ../../ezc/src/functions.h +generic.o: ../../pikotools/utf8/utf8.h ../../ezc/src/cache.h +generic.o: ../../ezc/src/pattern.h ../../ezc/src/patternparser.h misc.h +generic.o: localefilter.h locale.h ../../pikotools/space/spaceparser.h +generic.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h +generic.o: ../../pikotools/textstream/textstream.h +generic.o: ../../pikotools/space/space.h ../../pikotools/date/date.h +generic.o: ../../pikotools/convert/convert.h +generic.o: ../../pikotools/convert/inttostr.h +generic.o: ../../pikotools/membuffer/membuffer.h +generic.o: ../../pikotools/textstream/types.h htmltextstream.h +generic.o: ../../winix/core/textstream.h patterncacher.h +generic.o: ../../winix/core/item.h indexpatterns.h patterns.h +generic.o: changepatterns.h ../../winix/core/config.h +generic.o: ../../winix/core/htmlfilter.h ../../winix/core/cur.h +generic.o: ../../winix/core/request.h ../../winix/core/requesttypes.h +generic.o: ../../winix/core/error.h ../../winix/core/config.h +generic.o: ../../winix/core/textstream.h +generic.o: ../../winix/templates/htmltextstream.h +generic.o: ../../pikotools/space/spacetojson.h ../../winix/core/session.h +generic.o: ../../winix/core/user.h ../../winix/core/plugindata.h +generic.o: ../../winix/core/rebus.h ../../winix/core/ipban.h +generic.o: ../../winix/core/mount.h ../../winix/core/system.h +generic.o: ../../winix/core/job.h ../../winix/core/basethread.h +generic.o: ../../winix/core/synchro.h ../../winix/core/dirs.h +generic.o: ../../winix/core/dircontainer.h ../../winix/db/db.h +generic.o: ../../winix/db/dbbase.h ../../winix/db/dbconn.h +generic.o: ../../winix/db/dbtextstream.h ../../winix/core/error.h +generic.o: ../../winix/db/dbitemquery.h ../../winix/db/dbitemcolumns.h +generic.o: ../../winix/core/user.h ../../winix/core/group.h +generic.o: ../../winix/core/dircontainer.h ../../winix/core/ugcontainer.h +generic.o: ../../winix/core/log.h ../../winix/core/logmanipulators.h +generic.o: ../../winix/core/slog.h ../../winix/core/cur.h +generic.o: ../../winix/templates/locale.h ../../winix/notify/notify.h +generic.o: ../../winix/notify/notifypool.h ../../winix/templates/patterns.h +generic.o: ../../winix/notify/notifythread.h ../../winix/core/basethread.h +generic.o: ../../winix/notify/templatesnotify.h ../../winix/core/users.h +generic.o: ../../winix/core/ugcontainer.h ../../winix/core/lastcontainer.h +generic.o: ../../winix/core/mounts.h ../../winix/core/mountparser.h +generic.o: ../../winix/core/crypt.h ../../winix/core/run.h +generic.o: ../../winix/core/users.h ../../winix/core/groups.h +generic.o: ../../winix/core/group.h ../../winix/core/loadavg.h +generic.o: ../../winix/core/image.h ../../winix/core/threadmanager.h +generic.o: ../../winix/core/timezones.h ../../winix/core/timezone.h +generic.o: ../../winix/core/sessionmanager.h +generic.o: ../../winix/core/sessioncontainer.h +generic.o: ../../winix/core/ipbancontainer.h ../../winix/core/system.h +generic.o: ../../winix/core/htmlfilter.h ../../winix/core/request.h +generic.o: ../../winix/core/misc.h ../../winix/core/winix_const.h htmltextstream.o: htmltextstream.h ../../winix/core/textstream.h misc.h htmltextstream.o: localefilter.h locale.h ../../pikotools/space/spaceparser.h htmltextstream.o: ../../pikotools/space/space.h diff --git a/templates/Makefile.o.dep b/templates/Makefile.o.dep index 2acccb6..9d81df7 100644 --- a/templates/Makefile.o.dep +++ b/templates/Makefile.o.dep @@ -1 +1 @@ -o = adduser.o changepatterns.o config.o dir.o doc.o env.o filters.o htmltextstream.o indexpatterns.o insert.o ipban.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o passwd.o patterncacher.o patterns.o priv.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 +o = adduser.o changepatterns.o config.o dir.o doc.o env.o filters.o generic.o htmltextstream.o indexpatterns.o insert.o ipban.o item.o last.o locale.o localefilter.o login.o ls.o man.o misc.o miscspace.o mount.o passwd.o patterncacher.o patterns.o priv.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 diff --git a/templates/generic.cpp b/templates/generic.cpp new file mode 100644 index 0000000..c86dd54 --- /dev/null +++ b/templates/generic.cpp @@ -0,0 +1,237 @@ +/* + * This file is a part of Winix + * and is distributed under the 2-Clause BSD licence. + * Author: Tomasz Sowa + */ + +/* + * Copyright (c) 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 "templates.h" +#include "core/request.h" +#include "core/misc.h" + + +namespace Winix +{ + +namespace TemplatesFunctions +{ + + + +void ezc_false(Info & i) +{ + i.res = false; +} + + +void ezc_true(Info & i) +{ + i.res = true; +} + + +void ezc_and(Info & i) +{ + if( !i.params.empty() ) + { + i.res = true; + + for(size_t a=0 ; a < i.params.size() ; ++a) + { + if( !i.params[a].res ) + { + i.res = false; + break; + } + } + } +} + + +void ezc_any(Info & i) +{ + ezc_and(i); +} + + +void ezc_or(Info & i) +{ + i.res = false; + + for(size_t a=0 ; a < i.params.size() ; ++a) + { + if( i.params[a].res ) + { + i.res = true; + break; + } + } +} + + +void ezc_one(Info & i) +{ + ezc_or(i); +} + + +void ezc_not(Info & i) +{ + if( !i.params.empty() ) + i.res = !i.params[0].res; +} + + + +/* + * compare strings + */ +void cmp(Info & i) +{ + if( i.params.size() >= 2 ) + { + i.res = true; + + for(size_t a=0 ; a < i.params.size() - 1 ; ++a) + { + if( i.params[a].str != i.params[a+1].str ) + { + i.res = false; + break; + } + } + } +} + + + + + +// IMPROVE ME !! may we need such a filter too? +void trim(Info & i) +{ + for(size_t a=0 ; a < i.params.size() ; ++a) + { + // trimming with new lines too + TrimWhite(i.params[a].str, true); + i.out << R(i.params[a].str); + } +} + + + +void to_lower(Info & i) +{ + for(size_t a=0 ; a < i.params.size() ; ++a) + { + for(size_t z=0 ; z < i.params[a].str.size() ; ++z) + i.out << R(locale.ToSmall(i.params[a].str[z])); + } +} + + +void to_upper(Info & i) +{ + for(size_t a=0 ; a < i.params.size() ; ++a) + { + for(size_t z=0 ; z < i.params[a].str.size() ; ++z) + i.out << R(locale.ToCapital(i.params[a].str[z])); + } +} + + + +bool index_find_last_for_statement(Info & i, size_t & last_for_index) +{ + last_for_index = i.stack_index; + + do + { + if( i.stack_tab[last_for_index].is_for ) + return true; + } + while( last_for_index-- > 0 ); + +return false; +} + + + +void index(Info & i) +{ +size_t for_index; + + if( !index_find_last_for_statement(i, for_index) ) + return; + + if( i.params.size() != 1 ) + { + i.out << i.stack_tab[for_index].iter; + return; + } + + if( i.par == L"odd" ) + { + i.res = (i.stack_tab[for_index].iter & 1) == 1; + } + else + if( i.par == L"even" ) + { + i.res = (i.stack_tab[for_index].iter & 1) == 0; + } + else + if( i.par == L"first" ) + { + i.res = i.stack_tab[for_index].iter == 0; + } + else + if( IsSize(i.par, true) ) + { + + size_t number = static_cast(Tol(SkipWhite(i.par.c_str(), true))); + i.res = (i.stack_tab[for_index].iter == number); + } +} + + + +void str(Info & i) +{ + for(size_t a=0 ; a < i.params.size() ; ++a) + i.out << R(i.params[a].str); +} + + + + +} // namespace + +} // namespace Winix + diff --git a/templates/templates.cpp b/templates/templates.cpp index ca77890..72f5eaa 100644 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -307,6 +307,24 @@ void Templates::CreateFunctions() ezc_functions.Insert("fil_html_newline", fil_html_newline); + /* + generic functions + */ + ezc_functions.Insert("false", ezc_false); + ezc_functions.Insert("true", ezc_true); + ezc_functions.Insert("and", ezc_and); + ezc_functions.Insert("any", ezc_any); + ezc_functions.Insert("or", ezc_or); + ezc_functions.Insert("one", ezc_one); + ezc_functions.Insert("not", ezc_not); + ezc_functions.Insert("cmp", cmp); + ezc_functions.Insert("trim", trim); + ezc_functions.Insert("to_lower", to_lower); + ezc_functions.Insert("to_upper", to_upper); + ezc_functions.Insert("index", index); + ezc_functions.Insert("str", str); + + /* insert */ @@ -644,8 +662,6 @@ void Templates::CreateFunctions() ezc_functions.Insert("winix_req_per_sec_5", winix_req_per_sec_5); ezc_functions.Insert("winix_req_per_sec_15", winix_req_per_sec_15); ezc_functions.Insert("winix_show_content_in_full_window", winix_show_content_in_full_window); - ezc_functions.Insert("false", winix_false); - ezc_functions.Insert("true", winix_true); ezc_functions.Insert("winix_has_postvar", winix_has_postvar); ezc_functions.Insert("winix_postvar", winix_postvar); ezc_functions.Insert("winix_postvar_value_is", winix_postvar_value_is); @@ -654,7 +670,6 @@ void Templates::CreateFunctions() ezc_functions.Insert("winix_subdomain_is_empty", winix_subdomain_is_empty); ezc_functions.Insert("winix_subdomain_is_not_empty", winix_subdomain_is_not_empty); ezc_functions.Insert("winix_subdomain_is", winix_subdomain_is); - ezc_functions.Insert("str", str); ezc_functions.Insert("winix_tz_tab", winix_tz_tab); ezc_functions.Insert("winix_tz_tab_id", winix_tz_tab_id); ezc_functions.Insert("winix_tz_tab_name", winix_tz_tab_name); diff --git a/templates/templates.h b/templates/templates.h index 96b0efb..7b3a09a 100644 --- a/templates/templates.h +++ b/templates/templates.h @@ -220,6 +220,24 @@ namespace TemplatesFunctions void fil_html_newline(Info & i); + /* + generic functions + */ + void ezc_false(Info & i); + void ezc_true(Info & i); + void ezc_and(Info & i); + void ezc_any(Info & i); + void ezc_or(Info & i); + void ezc_one(Info & i); + void ezc_not(Info & i); + void cmp(Info & i); + void trim(Info & i); + void to_lower(Info & i); + void to_upper(Info & i); + void index(Info & i); + void str(Info & i); + + /* insert */ @@ -560,8 +578,6 @@ namespace TemplatesFunctions void winix_req_per_sec_5(Info & i); void winix_req_per_sec_15(Info & i); void winix_show_content_in_full_window(Info & i); - void winix_false(Info & i); - void winix_true(Info & i); void winix_has_postvar(Info & i); void winix_postvar(Info & i); void winix_postvar_value_is(Info & i); @@ -570,7 +586,6 @@ namespace TemplatesFunctions void winix_subdomain_is_empty(Info & i); void winix_subdomain_is_not_empty(Info & i); void winix_subdomain_is(Info & i); - void str(Info & i); void winix_tz_tab(Info & i); void winix_tz_tab_id(Info & i); void winix_tz_tab_name(Info & i); diff --git a/templates/winix.cpp b/templates/winix.cpp index 1ef60bd..01d1e1d 100644 --- a/templates/winix.cpp +++ b/templates/winix.cpp @@ -233,21 +233,6 @@ void winix_show_content_in_full_window(Info & i) -// the ezc function name is "false" -// ezc_functions.Insert("false", winix_false); -void winix_false(Info & i) -{ - i.res = false; -} - - -// the ezc function name is "true" -// ezc_functions.Insert("true", winix_true); -void winix_true(Info & i) -{ - i.res = true; -} - void winix_has_postvar(Info & i) { @@ -301,13 +286,6 @@ void winix_subdomain_is(Info & i) -// these functions are to be used with [is...] statements -void str(Info & i) -{ - for(size_t a=0 ; a