Support hexadecimal integer constants in expressions; add hex() function.

This commit is contained in:
Dianne Skoll
2025-09-11 17:02:22 -04:00
parent 9d999a0074
commit d15c8f106b
5 changed files with 60 additions and 2 deletions

View File

@@ -169,7 +169,7 @@
"baseyr" "catch" "catcherr" "char" "choose" "codepoint" "coerce" "columns" "const" "current" "date"
"datepart" "datetime" "dawn" "day" "daysinmon" "defined" "dosubst"
"dusk" "easterdate" "escape" "eval" "evaltrig" "filedate" "filedatetime"
"filedir" "filename" "getenv" "hebdate" "hebday" "hebmon" "hebyear"
"filedir" "filename" "getenv" "hebdate" "hebday" "hebmon" "hebyear" "hex"
"hour" "htmlescape" "htmlstriptags" "iif" "index" "isany" "isconst" "isdst"
"isleap" "isomitted" "language" "localtoutc" "lower" "max"
"mbasc" "mbindex" "mbstrlen" "mbsubstr" "min"

View File

@@ -2605,7 +2605,7 @@ as being the combination of \fBDATE\fR and \fBTIME\fR parts.
The following examples illustrate constants in \fBRemind\fR expressions:
.TP
.B INT constants
12, 36, \-10, 0, 1209
12, 36, \-10, 0, 1209, 0x1F, 0xfe00 (the last two demonstrate the use of hexadecimal constants)
.TP
.B STRING constants
"Hello there", "This is a test", "\\nHello\\tThere", ""
@@ -4055,6 +4055,11 @@ Support for Hebrew dates - see the section "THE HEBREW CALENDAR"
.B hebyear(dq_date)
Support for Hebrew dates - see the section "THE HEBREW CALENDAR"
.TP
.B hex(i_n)
Returns a STRING that is the hexadecimal representation of \fIn\fR.
There is no "0x" prefix and any letters in the returned value
are uppper-case.
.TP
.B hour(tq_time)
Returns the hour component of \fItime\fR.
.TP

View File

@@ -113,6 +113,7 @@ static int FHebdate (func_info *);
static int FHebday (func_info *);
static int FHebmon (func_info *);
static int FHebyear (func_info *);
static int FHex (func_info *);
static int FHour (func_info *);
static int FHtmlEscape (func_info *);
static int FHtmlStriptags (func_info *);
@@ -297,6 +298,7 @@ BuiltinFunc Func[] = {
{ "hebday", 1, 1, 0, FHebday, NULL },
{ "hebmon", 1, 1, 0, FHebmon, NULL },
{ "hebyear", 1, 1, 0, FHebyear, NULL },
{ "hex", 1, 1, 1, FHex, NULL },
{ "hour", 1, 1, 1, FHour, NULL },
{ "htmlescape", 1, 1, 1, FHtmlEscape, NULL },
{ "htmlstriptags",1, 1, 1, FHtmlStriptags, NULL },
@@ -734,6 +736,20 @@ static int FAsc(func_info *info)
return OK;
}
/***************************************************************/
/* */
/* FHex - return hexadecimal representation of an integer */
/* */
/***************************************************************/
static int FHex(func_info *info)
{
char buf[64];
ASSERT_TYPE(0, INT_TYPE);
snprintf(buf, sizeof(buf), "%X", (unsigned int) ARGV(0));
return RetStrVal(buf, info);
}
/***************************************************************/
/* */
/* FCodepoint - wide-character codepoint of start of str */

View File

@@ -813,6 +813,17 @@ REM MSG fib(30) = [fib(30)]
EOF
# Test hex constants
../src/remind -dh --flush -q - 2025-01-01 <<'EOF' >> ../tests/test.out 2>&1
BANNER %
SET $AddBlankLines 0
set a 0xfe + 0xef
rem msg a = [a]; hex(a) = [hex(a)]
rem msg hex(-1) = [hex(-1)]
set a 0x7fff
rem msg a = [a]; hex(a) = [hex(a)]
EOF
cmp -s ../tests/test.out ../tests/test.cmp
if [ "$?" = "0" ]; then
echo "Remind: Acceptance test PASSED"

View File

@@ -24635,6 +24635,7 @@ hebdate
hebday
hebmon
hebyear
hex
hour
htmlescape
htmlstriptags
@@ -39862,3 +39863,28 @@ Expression nodes high-water: 16
Parse level high-water: 25
Max expr node evaluations per line: 1000000
Total expression node evaluations: 3999940
a = 493; hex(a) = 1ED
hex(-1) = FFFFFFFF
a = 32767; hex(a) = 7FFF
Variable hash table statistics:
Entries: 1; Buckets: 7; Non-empty Buckets: 1
Maxlen: 1; Minlen: 0; Avglen: 0.143; Stddev: 0.350; Avg nonempty len: 1.000
Growths: 0; Shrinks: 0
Function hash table statistics:
Entries: 0; Buckets: 7; Non-empty Buckets: 0
Maxlen: 0; Minlen: 0; Avglen: 0.000; Stddev: 0.000; Avg nonempty len: 0.000
Growths: 0; Shrinks: 0
Dedupe hash table statistics:
Entries: 0; Buckets: 7; Non-empty Buckets: 0
Maxlen: 0; Minlen: 0; Avglen: 0.000; Stddev: 0.000; Avg nonempty len: 0.000
Growths: 0; Shrinks: 0
Translation hash table statistics:
Entries: 1; Buckets: 7; Non-empty Buckets: 1
Maxlen: 1; Minlen: 0; Avglen: 0.143; Stddev: 0.350; Avg nonempty len: 1.000
Growths: 0; Shrinks: 0
Expression nodes allocated: 256
Expression nodes high-water: 3
Expression nodes leaked: 0
Parse level high-water: 17
Max expr node evaluations per line: 3
Total expression node evaluations: 13