mirror of
https://github.com/gbdev/rgbds.git
synced 2026-10-06 04:05:38 +00:00
Add STRICMP case-insensitive string compare function (#2164)
This commit is contained in:
1 parent
d95e9260e4
commit
cf897aa065
4 files changed
+19
-1
No files matched your search
@@ -185,6 +185,7 @@ static UpperMap<int> const keywords{
|
||||
{"STRENDS", T_(OP_STRENDS) },
|
||||
{"STRFIND", T_(OP_STRFIND) },
|
||||
{"STRFMT", T_(OP_STRFMT) },
|
||||
{"STRICMP", T_(OP_STRICMP) },
|
||||
{"STRIN", T_(OP_STRIN) },
|
||||
{"STRLEN", T_(OP_STRLEN) },
|
||||
{"STRLWR", T_(OP_STRLWR) },
|
||||
|
||||
+9
-1
@@ -5,6 +5,8 @@
|
||||
%define api.token.constructor
|
||||
|
||||
%code requires {
|
||||
#include "platform.hpp"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
@@ -301,6 +303,7 @@
|
||||
%token OP_STRENDS "STRENDS"
|
||||
%token OP_STRFIND "STRFIND"
|
||||
%token OP_STRFMT "STRFMT"
|
||||
%token OP_STRICMP "STRICMP"
|
||||
%token OP_STRIN "STRIN"
|
||||
%token OP_STRLEN "STRLEN"
|
||||
%token OP_STRLWR "STRLWR"
|
||||
@@ -1483,7 +1486,12 @@ relocexpr_no_str:
|
||||
$$.makeNumber(fix_ATan2($3, $5, $6));
|
||||
}
|
||||
| OP_STRCMP LPAREN string COMMA string RPAREN {
|
||||
$$.makeNumber($3.compare($5));
|
||||
int result = $3.compare($5);
|
||||
$$.makeNumber(result < 0 ? -1 : result > 0 ? 1 : 0);
|
||||
}
|
||||
| OP_STRICMP LPAREN string COMMA string RPAREN {
|
||||
int result = strcasecmp($3.c_str(), $5.c_str());
|
||||
$$.makeNumber(result < 0 ? -1 : result > 0 ? 1 : 0);
|
||||
}
|
||||
| OP_STRFIND LPAREN string COMMA string RPAREN {
|
||||
size_t pos = $3.find($5);
|
||||
|
||||
Reference in new issue
Block a user