mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-17 23:08:40 +02:00
Implement htmlescape() built-in function.
This commit is contained in:
@@ -3074,6 +3074,10 @@ Support for Hebrew dates - see the section "THE HEBREW CALENDAR"
|
|||||||
.B hour(tq_time)
|
.B hour(tq_time)
|
||||||
Returns the hour component of \fItime\fR.
|
Returns the hour component of \fItime\fR.
|
||||||
.TP
|
.TP
|
||||||
|
.B htmlescape(s_str)
|
||||||
|
Returns a modified copy of \fIstr\fR where "<" is replaced with
|
||||||
|
"<"; ">" is replaced with ">" and "&" is replaced with "&"
|
||||||
|
.TP
|
||||||
.B iif(si_test1, x_arg1, [si_test2, x_arg2,...], x_default)
|
.B iif(si_test1, x_arg1, [si_test2, x_arg2,...], x_default)
|
||||||
If \fItest1\fR is not zero or the null string, returns \fIarg1\fR.
|
If \fItest1\fR is not zero or the null string, returns \fIarg1\fR.
|
||||||
Otherwise, if \fItest2\fR is not zero or the null string, returns
|
Otherwise, if \fItest2\fR is not zero or the null string, returns
|
||||||
|
|||||||
49
src/funcs.c
49
src/funcs.c
@@ -101,6 +101,7 @@ static int FHebday (func_info *);
|
|||||||
static int FHebmon (func_info *);
|
static int FHebmon (func_info *);
|
||||||
static int FHebyear (func_info *);
|
static int FHebyear (func_info *);
|
||||||
static int FHour (func_info *);
|
static int FHour (func_info *);
|
||||||
|
static int FHtmlEscape (func_info *);
|
||||||
static int FIif (func_info *);
|
static int FIif (func_info *);
|
||||||
static int FIndex (func_info *);
|
static int FIndex (func_info *);
|
||||||
static int FIsdst (func_info *);
|
static int FIsdst (func_info *);
|
||||||
@@ -265,6 +266,7 @@ BuiltinFunc Func[] = {
|
|||||||
{ "hebmon", 1, 1, 0, FHebmon },
|
{ "hebmon", 1, 1, 0, FHebmon },
|
||||||
{ "hebyear", 1, 1, 0, FHebyear },
|
{ "hebyear", 1, 1, 0, FHebyear },
|
||||||
{ "hour", 1, 1, 1, FHour },
|
{ "hour", 1, 1, 1, FHour },
|
||||||
|
{ "htmlescape", 1, 1, 1, FHtmlEscape },
|
||||||
{ "iif", 1, NO_MAX, 1, FIif },
|
{ "iif", 1, NO_MAX, 1, FIif },
|
||||||
{ "index", 2, 3, 1, FIndex },
|
{ "index", 2, 3, 1, FIndex },
|
||||||
{ "isany", 1, NO_MAX, 1, FIsAny },
|
{ "isany", 1, NO_MAX, 1, FIsAny },
|
||||||
@@ -2248,6 +2250,53 @@ static int FHebyear(func_info *info)
|
|||||||
RETVAL = y;
|
RETVAL = y;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************/
|
||||||
|
/* */
|
||||||
|
/* htmlescape - replace <. > and & by < > and & */
|
||||||
|
/* */
|
||||||
|
/****************************************************************/
|
||||||
|
|
||||||
|
static int FHtmlEscape(func_info *info)
|
||||||
|
{
|
||||||
|
DynamicBuffer dbuf;
|
||||||
|
char const *s;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
ASSERT_TYPE(0, STR_TYPE);
|
||||||
|
|
||||||
|
DBufInit(&dbuf);
|
||||||
|
|
||||||
|
s = ARGSTR(0);
|
||||||
|
while(*s) {
|
||||||
|
switch(*s) {
|
||||||
|
case '<':
|
||||||
|
r = DBufPuts(&dbuf, "<");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '>':
|
||||||
|
r = DBufPuts(&dbuf, ">");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '&':
|
||||||
|
r = DBufPuts(&dbuf, "&");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
r = DBufPutc(&dbuf, *s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (r != OK) {
|
||||||
|
DBufFree(&dbuf);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
r = RetStrVal(DBufValue(&dbuf), info);
|
||||||
|
DBufFree(&dbuf);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/* FEasterdate - calc. easter Sunday from a year. */
|
/* FEasterdate - calc. easter Sunday from a year. */
|
||||||
|
|||||||
@@ -4786,6 +4786,28 @@ FUNSET circle square rectangle
|
|||||||
SET a square(5)
|
SET a square(5)
|
||||||
../tests/test.rem(867): Undefined function: `square'
|
../tests/test.rem(867): Undefined function: `square'
|
||||||
|
|
||||||
|
# htmlescape
|
||||||
|
set a htmlescape("foo")
|
||||||
|
htmlescape("foo") => "foo"
|
||||||
|
REM MSG [a]
|
||||||
|
../tests/test.rem(871): Trig = Saturday, 16 February, 1991
|
||||||
|
a => "foo"
|
||||||
|
foo
|
||||||
|
|
||||||
|
set a htmlescape("<&>")
|
||||||
|
htmlescape("<&>") => "<&>"
|
||||||
|
REM MSG [a]
|
||||||
|
../tests/test.rem(873): Trig = Saturday, 16 February, 1991
|
||||||
|
a => "<&>"
|
||||||
|
<&>
|
||||||
|
|
||||||
|
set a htmlescape("@&^#*@&^##$*&@><><@#@#><@#>%%_#$foobarquux")
|
||||||
|
htmlescape("@&^#*@&^##$*&@><><@#@#><@#>%%_#$foobarqu"...) => "@&^#*@&^##$*&@><>&l"...
|
||||||
|
REM MSG [a]
|
||||||
|
../tests/test.rem(875): Trig = Saturday, 16 February, 1991
|
||||||
|
a => "@&^#*@&^##$*&@><>&l"...
|
||||||
|
@&^#*@&^##$*&@><><@#@#><@#>%_#$foobarquux
|
||||||
|
|
||||||
# Don't want Remind to queue reminders
|
# Don't want Remind to queue reminders
|
||||||
EXIT
|
EXIT
|
||||||
|
|
||||||
|
|||||||
@@ -866,6 +866,13 @@ FUNSET circle square rectangle
|
|||||||
# Should fail
|
# Should fail
|
||||||
SET a square(5)
|
SET a square(5)
|
||||||
|
|
||||||
|
# htmlescape
|
||||||
|
set a htmlescape("foo")
|
||||||
|
REM MSG [a]
|
||||||
|
set a htmlescape("<&>")
|
||||||
|
REM MSG [a]
|
||||||
|
set a htmlescape("@&^#*@&^##$*&@><><@#@#><@#>%%_#$foobarquux")
|
||||||
|
REM MSG [a]
|
||||||
# Don't want Remind to queue reminders
|
# Don't want Remind to queue reminders
|
||||||
EXIT
|
EXIT
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user