aboutsummaryrefslogtreecommitdiff
path: root/jim.c
diff options
context:
space:
mode:
authorD. Bohdan <dbohdan@dbohdan.com>2020-09-07 09:14:44 +0000
committerSteve Bennett <steveb@workware.net.au>2020-09-23 10:39:12 +1000
commitecfb322f84ee7af404a43846c655e7145091ecfc (patch)
treeeff835f78d87964f5c887d4db24afbc63c20f449 /jim.c
parent0a6e801f1425225ba4b52fe91d5b75afda998a1a (diff)
downloadjimtcl-ecfb322f84ee7af404a43846c655e7145091ecfc.zip
jimtcl-ecfb322f84ee7af404a43846c655e7145091ecfc.tar.gz
jimtcl-ecfb322f84ee7af404a43846c655e7145091ecfc.tar.bz2
core: implement string comparison operators
TIP 461
Diffstat (limited to 'jim.c')
-rw-r--r--jim.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/jim.c b/jim.c
index 1a47200..d156a09 100644
--- a/jim.c
+++ b/jim.c
@@ -7984,15 +7984,19 @@ enum
JIM_EXPROP_STRNE,
JIM_EXPROP_STRIN,
JIM_EXPROP_STRNI,
+ JIM_EXPROP_STRLT,
+ JIM_EXPROP_STRGT,
+ JIM_EXPROP_STRLE,
+ JIM_EXPROP_STRGE,
/* Unary operators (numbers) */
- JIM_EXPROP_NOT, /* 47 */
+ JIM_EXPROP_NOT, /* 51 */
JIM_EXPROP_BITNOT,
JIM_EXPROP_UNARYMINUS,
JIM_EXPROP_UNARYPLUS,
/* Functions */
- JIM_EXPROP_FUNC_INT, /* 51 */
+ JIM_EXPROP_FUNC_INT, /* 55 */
JIM_EXPROP_FUNC_WIDE,
JIM_EXPROP_FUNC_ABS,
JIM_EXPROP_FUNC_DOUBLE,
@@ -8001,7 +8005,7 @@ enum
JIM_EXPROP_FUNC_SRAND,
/* math functions from libm */
- JIM_EXPROP_FUNC_SIN, /* 65 */
+ JIM_EXPROP_FUNC_SIN, /* 69 */
JIM_EXPROP_FUNC_COS,
JIM_EXPROP_FUNC_TAN,
JIM_EXPROP_FUNC_ASIN,
@@ -8564,7 +8568,7 @@ static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprNode *node)
{
Jim_Obj *A, *B;
jim_wide wC;
- int rc;
+ int comp, rc;
if ((rc = JimExprGetTerm(interp, node->left, &A)) != JIM_OK) {
return rc;
@@ -8582,6 +8586,21 @@ static int JimExprOpStrBin(Jim_Interp *interp, struct JimExprNode *node)
wC = !wC;
}
break;
+ case JIM_EXPROP_STRLT:
+ case JIM_EXPROP_STRGT:
+ case JIM_EXPROP_STRLE:
+ case JIM_EXPROP_STRGE:
+ comp = Jim_StringCompareObj(interp, A, B, 0);
+ if (node->type == JIM_EXPROP_STRLT) {
+ wC = comp == -1;
+ } else if (node->type == JIM_EXPROP_STRGT) {
+ wC = comp == 1;
+ } else if (node->type == JIM_EXPROP_STRLE) {
+ wC = comp == -1 || comp == 0;
+ } else /* JIM_EXPROP_STRGE */ {
+ wC = comp == 0 || comp == 1;
+ }
+ break;
case JIM_EXPROP_STRIN:
wC = JimSearchList(interp, B, A);
break;
@@ -8727,6 +8746,13 @@ static const struct Jim_ExprOperator Jim_ExprOperators[] = {
OPRINIT("in", 55, 2, JimExprOpStrBin),
OPRINIT("ni", 55, 2, JimExprOpStrBin),
+ /* Precedence must be higher than ==, !=, eq, ne but lower than
+ <, >, <=, >= */
+ OPRINIT("lt", 75, 2, JimExprOpStrBin),
+ OPRINIT("gt", 75, 2, JimExprOpStrBin),
+ OPRINIT("le", 75, 2, JimExprOpStrBin),
+ OPRINIT("ge", 75, 2, JimExprOpStrBin),
+
OPRINIT_ATTR("!", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR("~", 150, 1, JimExprOpIntUnary, OP_RIGHT_ASSOC),
OPRINIT_ATTR(" -", 150, 1, JimExprOpNumUnary, OP_RIGHT_ASSOC),