Heavy work on while tag. Still needs work.

This commit is contained in:
Brad Arant committed 2024-11-04 16:48:14 -08:00
1 parent b08d2b59eb
commit ed00a330a4
5 files changed
+46 -25

No files matched your search

+12 -6
View File
@@ -70,7 +70,8 @@ namespace jet {
unsigned int seed = (unsigned int)clock();
doubleValue = (double) rand_r(&seed) / (RAND_MAX + 1.0);
isNumber = true;
string = std::format("{}", doubleValue);
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else if(in.ifNext("true")) {
boolean = true;
string = "true";
@@ -79,7 +80,7 @@ namespace jet {
string = "false";
} else if(in.startsWithNumber()) {
doubleValue = in.asDouble();
string = std::format("{}", doubleValue);
string = std::format("{:.12f}", doubleValue);
isNumber = true;
} else if(in.ifNext("'")) {
string = in.getTokenExclude("'");
@@ -116,6 +117,7 @@ namespace jet {
if(in.ifNext("<")) {
Operand op(in);
if(isNumber && op.isNumber) {
std::cout << doubleValue << " < " << op.doubleValue << std::endl;
if(doubleValue < op.doubleValue) {
boolean = true;
isNumber = false;
@@ -238,7 +240,8 @@ namespace jet {
Operand op(in);
if(op.isNumber) {
doubleValue += op.doubleValue;
string = std::format("{}", doubleValue);
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("operand is not a number.");
} else
@@ -248,7 +251,8 @@ namespace jet {
Operand op(in);
if(op.isNumber) {
doubleValue -= op.doubleValue;
string = std::format("{}", doubleValue);
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("operand is not a number.");
} else
@@ -258,7 +262,8 @@ namespace jet {
Operand op(in);
if(op.isNumber) {
doubleValue *= op.doubleValue;
string = std::format("{}", doubleValue);
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("operand is not a number.");
} else
@@ -268,7 +273,8 @@ namespace jet {
Operand op(in);
if(op.isNumber) {
doubleValue /= op.doubleValue;
string = std::format("{}", doubleValue);
string = std::format("{:.12f}", doubleValue);
string.removeTrailingZeros();
} else
throw coreutils::Exception("operand is not a number.");
} else
-1
View File
@@ -34,7 +34,6 @@ namespace jet {
if(in.ifNext("<")) {
name = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_!");
if(in.startsWith(" ") || in.startsWith("/") || in.startsWith(">")) {
coreutils::Log(coreutils::LOG_DEBUG_1) << "Processing tag: " << name;
bool finished = false;
while(!finished) {
in.skipWhitespace();
+23 -16
View File
@@ -9,24 +9,17 @@ namespace jet {
coreutils::MString result;
bool booleanResult = false;
bool exprMethod = false;
if(variableDefined("value1")) {
if(variableDefined("expr"))
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
if(variableDefined("value2")) {
if(variableDefined("type")) {
}
else
throw coreutils::Exception("type expected if value1 and value2 specified.");
}
else
throw coreutils::Exception("either value1 or expr can be specified but not both.");
if(!variableDefined("value2"))
throw coreutils::Exception("value2 required if value1 specified.");
if(!variableDefined("type"))
throw coreutils::Exception("type required for a value1 and value2 comparison.");
if(!variableDefined("type"))
throw coreutils::Exception("type expected if value1 and value2 specified.");
int rc = variables["value1"].compare(variables["value2"]);
if(((variables["type"] == "eq") && (rc == 0)) ||
((variables["type"] == "ne") && (rc != 0)) ||
@@ -39,19 +32,33 @@ namespace jet {
throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'.");
}
else if(variableDefined("expr")) {
if(variableDefined("value2"))
throw coreutils::Exception("value2 should not be specified with expr.");
if(variableDefined("type"))
throw coreutils::Exception("type should not be specified with expr.");
exprMethod = true;
booleanResult = Operand(variables["expr"]).boolean;
}
while(booleanResult) {
processContainer(container);
container.reset();
if(exprMethod) {
variables["expr"].reset();
booleanResult = Operand(variables["expr"]).boolean;
} else {
booleanResult = false;
int rc = variables["value1"].compare(variables["value2"]);
if(((variables["type"] == "eq") && (rc == 0)) ||
((variables["type"] == "ne") && (rc != 0)) ||
((variables["type"] == "lt") && (rc == -1)) ||
((variables["type"] == "le") && (rc != 1)) ||
((variables["type"] == "gt") && (rc == 1)) ||
((variables["type"] == "ge") && (rc != -1)))
booleanResult = true;
}
}
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
#!./jet-2.0
#!../jet-2.0
<jet cgi="true" name1="localname" filterblanklines="true" trimlines="true">
<for name="ix" start="1" end="5" step="1">
<for name="ix" start="1" end="5" step=".1">
-->#[ix]<--
</for>
</jet>
+9
View File
@@ -0,0 +1,9 @@
#!../jet-2.0
<jet cgi="false" name1="localname" filterblanklines="true" trimlines="true">
<set name="ix" value="1" />
<while expr="$[ix]<10">
<set name="check" expr="$[ix]<10" />
-->$[check]-$[ix]<--
<set name="ix" expr="$[ix]+1" />
</while>
</jet>