Added LEFT() expression function.

This commit is contained in:
Brad Arant 2024-10-01 07:41:05 -07:00
parent 8299aeaea9
commit fa711ddf86
3 changed files with 14 additions and 5 deletions

View File

@ -11,16 +11,12 @@ namespace jet {
in.skipWhitespace();
// std::cout << "op: [" << in.unparsed() << "]" << std::endl;
if(in.ifNext("(")) {
// std::cout << "(" << in.unparsed() << std::endl;
Operand op(in);
string = op.string;
doubleValue = op.doubleValue;
if(!in.ifNext(")"))
throw coreutils::Exception("expected ) in expression.");
// std::cout << ")" << in.unparsed() << std::endl;
}
if(in.ifNext("SUBSTRING")) {
@ -42,7 +38,17 @@ namespace jet {
else
throw coreutils::Exception("Expecting ) at end of substring expression.");
} else if(in.ifNext("LEFT")) {
if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for LEFT parameters.");
Operand parm1(in);
if(!in.ifNext(","))
throw coreutils::Exception("Expecting , in LEFT expression.");
Operand parm2(in);
if(in.ifNext(")")) {
string = parm1.string.substring(0, parm2.string.asInteger());
}
else
throw coreutils::Exception("Expecting ) at end of LEFT expression.");
} else if(in.ifNext("RIGHT")) {
} else if(in.ifNext("TRIM")) {

BIN
jet-2.0

Binary file not shown.

View File

@ -21,6 +21,9 @@
<set name="divisor" value="8" />
<set name="nested" expr="(2*(4+4)/$[divisor])*32" />
$[nested]
<set name="numbers">0123456789</set>
<set name="lefty" expr="LEFT('$[numbers]',5)" />
lefty=[$[lefty]]
substring('abcdefg', 1, 3)=[$[theexpr]]
5+3=($[addition])
5-3($[subtraction])