updated: to the new Ezc API

removed statements: [if-index ...] [is ...] [is-no ...]
added:   generic ezc functions:
         and, any (the same as and), or, one (the same as or), not, cmp, trim
         to_lower, to_upper, index
changed: in misc:
         added treat_new_line_as_white flag to IsWhite() SkipWhite() and TrimWhite()
         TrimWhite(), TrimFirst(), TrimLast(), Trim() are using only wide characters now
         (they were templates before)
         added: IsInt(), IsSize(), IsFloat()
changed: version to 0.6.4






git-svn-id: svn://ttmath.org/publicrep/winix/trunk@989 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2014-11-02 17:47:34 +00:00
parent db5572e864
commit 8f8defe0de
18 changed files with 589 additions and 149 deletions

File diff suppressed because one or more lines are too long

View File

@ -51,7 +51,7 @@ namespace Winix
namespace misc_private namespace misc_private
{ {
// white_chars table should be sorted // 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, static const wchar_t white_chars[] = { 0x0009, 0x000B, 0x000C, 0x000D, 0x0020, 0x0085, 0x00A0,
0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x1680, 0x180E, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004,
0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028, 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) int Toi(const std::string & str, int base)
{ {
return Toi(str.c_str(), 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; using misc_private::white_chars;
@ -481,6 +490,9 @@ using misc_private::white_chars;
size_t o1 = 0; size_t o1 = 0;
size_t o2 = len - 1; 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] ) if( c < white_chars[o1] || c > white_chars[o2] )
return false; return false;
@ -513,13 +525,7 @@ bool IsWhite(const wchar_t * str, bool treat_new_line_as_white)
{ {
for( ; *str != 0 ; ++str ) for( ; *str != 0 ; ++str )
{ {
if( *str == '\n' ) if( !IsWhite(*str, treat_new_line_as_white) )
{
if( !treat_new_line_as_white )
return false;
}
else
if( !IsWhite(*str) )
return false; 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 ; i<s.size() && IsWhite(s[i], trim_new_line_too) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}
const wchar_t * SkipWhite(const wchar_t * s, bool treat_new_line_as_white)
{
while( IsWhite(*s, treat_new_line_as_white) )
++s;
return s;
}
void TrimFirst(std::wstring & s, wchar_t c)
{
size_t i;
if( s.empty() )
return;
// looking for the 'c' characters at the beginning
for(i=0 ; i<s.size() && s[i]==c ; ++i);
// deleting the 'c' characters at the beginning
if( i != 0 )
s.erase(0, i);
}
void TrimLast(std::wstring & s, wchar_t c)
{
size_t 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, 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) 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) 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) wchar_t ToSmall(wchar_t c)
{ {

View File

@ -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 wchar_t * str, bool treat_new_line_as_white = false);
bool IsWhite(const std::wstring & 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); bool IsLastSlash(const std::wstring & path);
template<class StringType>
void TrimWhite(StringType & s) /*
{ * returns true if str is an integer number
typename StringType::size_type i; * white strings at the beginning and at the end are ignored
* e.g. returns true for:
if( s.empty() ) * " 10 "
return; * " -20 "
* e.g. returns false for:
// looking for white characters at the end * ""
for(i=s.size()-1 ; i>0 && IsWhite(s[i]) ; --i); * "- 20"
* "z"
if( i==0 && IsWhite(s[i]) ) */
{ bool IsInt(const wchar_t * str, bool treat_new_line_as_white = false);
// the whole string has white characters bool IsInt(const std::wstring & str, bool treat_new_line_as_white = false);
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<s.size() && IsWhite(s[i]) ; ++i);
// deleting white characters at the beginning
if( i != 0 )
s.erase(0, i);
}
template<class StringType> /*
void TrimFirst(StringType & s, wchar_t c) * returns true if str is a non-negative integer number
{ * white strings at the beginning and at the end are ignored
typename StringType::size_type i; * e.g. returns true for:
* " 0 "
if( s.empty() ) * " 10 "
return; * " 20 "
* e.g. returns false for:
// looking for the 'c' characters at the beginning * ""
for(i=0 ; i<s.size() && s[i]==c ; ++i); * " -20 "
* "z"
// deleting the 'c' characters at the beginning */
if( i != 0 ) bool IsSize(const wchar_t * str, bool treat_new_line_as_white = false);
s.erase(0, i); bool IsSize(const std::wstring & str, bool treat_new_line_as_white = false);
}
template<class StringType> /*
void TrimLast(StringType & s, wchar_t c) * returns true if str is a floating point number
{ * white strings at the beginning and at the end are ignored
typename StringType::size_type i; * as a decimal comma can be a dot or a comma
* e.g. returns true for:
if( s.empty() ) * " 10 "
return; * " -20.3 "
* " 30,5 "
// looking for the 'c' characters at the end * e.g. returns false for:
for(i=s.size()-1 ; i>0 && s[i]==c ; --i); * ""
* "- 20.1"
if( i==0 && s[i]==c ) * "20.1.2"
{ * "z"
// the whole string has the 'c' characters */
s.clear(); bool IsFloat(const wchar_t * str, bool treat_new_line_as_white = false);
return; bool IsFloat(const std::wstring & str, bool treat_new_line_as_white = false);
}
// deleting 'c' characters at the end
if( i != s.size() - 1 )
s.erase(i+1, StringType::npos);
}
template<class StringType>
void Trim(StringType & s, wchar_t c)
{
if( s.empty() )
return;
TrimLast(s, c);
TrimFirst(s, c);
}
void Overwrite(std::string & str); void Overwrite(std::string & str);
@ -391,8 +367,7 @@ bool was_comma = false;
wchar_t ToSmall(wchar_t c); wchar_t ToSmall(wchar_t c);
void ToSmall(std::wstring & s); void ToSmall(std::wstring & s);
const char * SkipWhite(const char * s);
const wchar_t * SkipWhite(const wchar_t * s);

View File

@ -42,7 +42,7 @@ namespace Winix
#define WINIX_VER_MAJOR 0 #define WINIX_VER_MAJOR 0
#define WINIX_VER_MINOR 6 #define WINIX_VER_MINOR 6
#define WINIX_VER_REVISION 3 #define WINIX_VER_REVISION 4

View File

@ -18,7 +18,7 @@
[# add to styles] [# add to styles]
<select name="localeid" style="width: 250px;"> <select name="localeid" style="width: 250px;">
[for winix_locale_tab] [for winix_locale_tab]
<option value="[winix_locale_tab_id]" [is user_locale_id winix_locale_tab_id]selected="selected"[end]>[winix_locale_tab_name]</option> <option value="[winix_locale_tab_id]" [if cmp [user_locale_id] [winix_locale_tab_id]]selected="selected"[end]>[winix_locale_tab_name]</option>
[end] [end]
</select> </select>

View File

@ -14,7 +14,7 @@
</tr> </tr>
[for user_tab] [for user_tab]
<tr class="[if-index odd]roweven[else]rowodd[end]"> <tr class="[if index "odd"]roweven[else]rowodd[end]">
<td>[user_tab_index]</td> <td>[user_tab_index]</td>
<td>[user_tab_name]</td> <td>[user_tab_name]</td>
<td>[if user_tab_is_super_user]{pw_table_yes}[end]</td> <td>[if user_tab_is_super_user]{pw_table_yes}[end]</td>

View File

@ -36,7 +36,7 @@
[# is it correct? may give this 'if' only to /-/thumb param? ] [# is it correct? may give this 'if' only to /-/thumb param? ]
[if item_tab_has_thumb]<img src="[item_tab_link]/-/thumb" alt="[item_tab_subject]">[end] [if item_tab_has_thumb]<img src="[item_tab_link]/-/thumb" alt="[item_tab_subject]">[end]
[item_tab_url] [is-no item_tab_subject str ""]<span class="winix_sort_item_title">({sort_item_subject}: [item_tab_subject])</span>[end] [item_tab_url] [if not [cmp [item_tab_subject] [str ""]]]<span class="winix_sort_item_title">({sort_item_subject}: [item_tab_subject])</span>[end]
</li> </li>
[end] [end]
</ul> </ul>

View File

@ -23,7 +23,7 @@
[for thread_sort_tab] [for thread_sort_tab]
<div class="winix_threadbox[if-index even] winix_threadboxcolor[end]"> <div class="winix_threadbox[if index "even"] winix_threadboxcolor[end]">
[if thread_sort_tab_can_write]<a class="winix_threadedit" href="[thread_sort_tab_link]/emacs" rel="nofollow">\[{edit}\]</a>[end] [if thread_sort_tab_can_write]<a class="winix_threadedit" href="[thread_sort_tab_link]/emacs" rel="nofollow">\[{edit}\]</a>[end]
[if thread_mount_arg_is "subject"]<h2[if thread_mount_arg_is "info"] class="winix_withinfo"[end]>[thread_sort_tab_subject]</h2>[end] [if thread_mount_arg_is "subject"]<h2[if thread_mount_arg_is "info"] class="winix_withinfo"[end]>[thread_sort_tab_subject]</h2>[end]
[if thread_mount_arg_is "info"][include "thread_sort_tab_info.html"][end] [if thread_mount_arg_is "info"][include "thread_sort_tab_info.html"][end]

View File

@ -56,7 +56,7 @@
[for thread_sort_tab] [for thread_sort_tab]
<div class="threadbox[if-index odd] threadboxcolor[end]"> <div class="threadbox[if index "odd"] threadboxcolor[end]">
[if thread_sort_tab_can_write]<a class="threadedit" href="[thread_sort_tab_link]/emacs" rel="nofollow">\[{edit}\]</a>[end] [if thread_sort_tab_can_write]<a class="threadedit" href="[thread_sort_tab_link]/emacs" rel="nofollow">\[{edit}\]</a>[end]
[if thread_mount_arg_is "subject"]<h2[if thread_mount_arg_is "info"] class="withinfo"[end]>[thread_sort_tab_subject]</h2>[end] [if thread_mount_arg_is "subject"]<h2[if thread_mount_arg_is "info"] class="withinfo"[end]>[thread_sort_tab_subject]</h2>[end]
[if thread_mount_arg_is "info"][include "thread_sort_tab_info.html"][end] [if thread_mount_arg_is "info"][include "thread_sort_tab_info.html"][end]

View File

@ -18,7 +18,7 @@
[# add to styles] [# add to styles]
<select name="timezoneid" style="width: 250px;"> <select name="timezoneid" style="width: 250px;">
[for winix_tz_tab] [for winix_tz_tab]
<option value="[winix_tz_tab_id]" [is user_time_zone_id winix_tz_tab_id]selected="selected"[end]>UTC[winix_tz_tab_offset_hour_min] [winix_tz_tab_name]</option> <option value="[winix_tz_tab_id]" [if cmp [user_time_zone_id] [winix_tz_tab_id]]selected="selected"[end]>UTC[winix_tz_tab_offset_hour_min] [winix_tz_tab_name]</option>
[end] [end]
</select> </select>

View File

@ -1,4 +1,4 @@
<p class="[if-index odd]winix_itemtabinfo[else][if thread_mount_arg_is "subject"]winix_itemtabinfo[else]winix_itemtabinfo2[end][end]"> <p class="[if index "odd"]winix_itemtabinfo[else][if thread_mount_arg_is "subject"]winix_itemtabinfo[else]winix_itemtabinfo2[end][end]">
{added_by}: [item_tab_user], [item_tab_date_creation_nice][if-no item_tab_dates_equal], {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] {last_modified}[if-one item_tab_users_different] {by}: [item_tab_modification_user],[else]:[end]

View File

@ -1,4 +1,4 @@
<p class="[if-index even]winix_itemtabinfo[else][if thread_mount_arg_is "subject"]winix_itemtabinfo[else]winix_itemtabinfo2[end][end]"> <p class="[if index "even"]winix_itemtabinfo[else][if thread_mount_arg_is "subject"]winix_itemtabinfo[else]winix_itemtabinfo2[end][end]">
{added_by}: [thread_sort_tab_user], [thread_sort_tab_date_creation_nice][if-no thread_sort_tab_dates_equal], {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] {last_modified}[if thread_sort_tab_users_different] {by}: [thread_sort_tab_modification_user],[else]:[end]

View File

@ -353,6 +353,57 @@ filters.o: ../../winix/core/sessioncontainer.h
filters.o: ../../winix/core/ipbancontainer.h ../../winix/core/system.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/htmlfilter.h ../../winix/core/misc.h
filters.o: ../../winix/core/winix_const.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: htmltextstream.h ../../winix/core/textstream.h misc.h
htmltextstream.o: localefilter.h locale.h ../../pikotools/space/spaceparser.h htmltextstream.o: localefilter.h locale.h ../../pikotools/space/spaceparser.h
htmltextstream.o: ../../pikotools/space/space.h htmltextstream.o: ../../pikotools/space/space.h

View File

@ -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

237
templates/generic.cpp Normal file
View File

@ -0,0 +1,237 @@
/*
* 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) 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<size_t>(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

View File

@ -307,6 +307,24 @@ void Templates::CreateFunctions()
ezc_functions.Insert("fil_html_newline", fil_html_newline); 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 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_5", winix_req_per_sec_5);
ezc_functions.Insert("winix_req_per_sec_15", winix_req_per_sec_15); 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("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_has_postvar", winix_has_postvar);
ezc_functions.Insert("winix_postvar", winix_postvar); ezc_functions.Insert("winix_postvar", winix_postvar);
ezc_functions.Insert("winix_postvar_value_is", winix_postvar_value_is); 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_empty", winix_subdomain_is_empty);
ezc_functions.Insert("winix_subdomain_is_not_empty", winix_subdomain_is_not_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("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", winix_tz_tab);
ezc_functions.Insert("winix_tz_tab_id", winix_tz_tab_id); ezc_functions.Insert("winix_tz_tab_id", winix_tz_tab_id);
ezc_functions.Insert("winix_tz_tab_name", winix_tz_tab_name); ezc_functions.Insert("winix_tz_tab_name", winix_tz_tab_name);

View File

@ -220,6 +220,24 @@ namespace TemplatesFunctions
void fil_html_newline(Info & i); 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 insert
*/ */
@ -560,8 +578,6 @@ namespace TemplatesFunctions
void winix_req_per_sec_5(Info & i); void winix_req_per_sec_5(Info & i);
void winix_req_per_sec_15(Info & i); void winix_req_per_sec_15(Info & i);
void winix_show_content_in_full_window(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_has_postvar(Info & i);
void winix_postvar(Info & i); void winix_postvar(Info & i);
void winix_postvar_value_is(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_empty(Info & i);
void winix_subdomain_is_not_empty(Info & i); void winix_subdomain_is_not_empty(Info & i);
void winix_subdomain_is(Info & i); void winix_subdomain_is(Info & i);
void str(Info & i);
void winix_tz_tab(Info & i); void winix_tz_tab(Info & i);
void winix_tz_tab_id(Info & i); void winix_tz_tab_id(Info & i);
void winix_tz_tab_name(Info & i); void winix_tz_tab_name(Info & i);

View File

@ -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) 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<i.params.size() ; ++a)
i.out << i.params[a].str;
}