Add STRSTARTS and STRENDS functions (#2159)

This commit is contained in:
Rangi authored and GitHub committed 2026-09-26 19:04:14 +02:00
1 parent 03c71ced93
commit 548a11c3ef
4 files changed
+26 -1

No files matched your search

+2
View File
@@ -180,6 +180,7 @@ static UpperMap<int> const keywords{
{"STRCAT", T_(OP_STRCAT) },
{"STRCHAR", T_(OP_STRCHAR) },
{"STRCMP", T_(OP_STRCMP) },
{"STRENDS", T_(OP_STRENDS) },
{"STRFIND", T_(OP_STRFIND) },
{"STRFMT", T_(OP_STRFMT) },
{"STRIN", T_(OP_STRIN) },
@@ -189,6 +190,7 @@ static UpperMap<int> const keywords{
{"STRRIN", T_(OP_STRRIN) },
{"STRRPL", T_(OP_STRRPL) },
{"STRSLICE", T_(OP_STRSLICE) },
{"STRSTARTS", T_(OP_STRSTARTS) },
{"STRSUB", T_(OP_STRSUB) },
{"STRUPR", T_(OP_STRUPR) },
+8
View File
@@ -296,6 +296,7 @@
%token OP_STRCAT "STRCAT"
%token OP_STRCHAR "STRCHAR"
%token OP_STRCMP "STRCMP"
%token OP_STRENDS "STRENDS"
%token OP_STRFIND "STRFIND"
%token OP_STRFMT "STRFMT"
%token OP_STRIN "STRIN"
@@ -305,6 +306,7 @@
%token OP_STRRIN "STRRIN"
%token OP_STRRPL "STRRPL"
%token OP_STRSLICE "STRSLICE"
%token OP_STRSTARTS "STRSTARTS"
%token OP_STRSUB "STRSUB"
%token OP_STRUPR "STRUPR"
%token OP_TAN "TAN"
@@ -1480,6 +1482,12 @@ relocexpr_no_str:
size_t pos = $3.rfind($5);
$$.makeNumber(pos != std::string::npos ? pos : -1);
}
| OP_STRSTARTS LPAREN string COMMA string RPAREN {
$$.makeNumber($3.starts_with($5));
}
| OP_STRENDS LPAREN string COMMA string RPAREN {
$$.makeNumber($3.ends_with($5));
}
| OP_STRIN LPAREN string COMMA string RPAREN {
warning(WARNING_OBSOLETE, "`STRIN` is deprecated; use 0-indexed `STRFIND` instead");
size_t pos = $3.find($5);