add # (string length) operator

This commit is contained in:
2018-05-02 15:13:29 +02:00
parent cc598bb620
commit 3613328132
2 changed files with 23 additions and 3 deletions
+12 -3
View File
@@ -29,7 +29,7 @@ static int parseValue(const char **pp, long *v)
o = *p;
if (memchr("+-~!", o, 4))
{
/* handle unary operators */
/* unary operators */
p++;
if (!parseValue(&p, &val)) return 0; /* no valid value */
if (exprDebug) printf("parseValue: %c %ld\n", o, val);
@@ -39,15 +39,24 @@ static int parseValue(const char **pp, long *v)
}
else if (o == '(')
{
/* handle sub-expression */
/* sub-expression */
p++;
if (parseExpr(&p, &val) < 0) return 0; /* no valid expression */
skipSpace(p);
if (*p++ != ')') return 0; /* missing ) */
}
else if (o == '#')
{
/* string length operator */
p++;
if (exprDebug) printf("parseValue: string length of %s\n", p);
if (*p == '"' || *p == '\'')
val = parseString(&p, NULL);
else return 0;
}
else
{
/* get number */
/* number */
char *e;
val = strtol(p, &e, 0);
if (e == p) return 0; /* no number */
+11
View File
@@ -78,3 +78,14 @@ x="Hello World"[7,-1]
x='\"\\x'[2]
# $(x) should be: x
x=#"Hello World"
# $(x) should be: 11
x=#"Hello World"[2:8]
# $(x) should be: 6
x=#Hello World
# $(x) should be: #Hello World