Fixed some Expression and Operand memory issues.

This commit is contained in:
Brad Arant 2024-09-26 16:58:55 -07:00
parent 3db9227adc
commit 5a97da3d1c
8 changed files with 10 additions and 11 deletions

View File

@ -15,7 +15,7 @@ namespace jet {
double getNumericResult(); double getNumericResult();
coreutils::ZString getStringResult(); coreutils::ZString getStringResult();
bool boolean; bool boolean;
coreutils::ZString string; coreutils::MString string;
char *operation; char *operation;
}; };

View File

@ -90,7 +90,7 @@ namespace jet {
void Global::outputHeaders() { void Global::outputHeaders() {
if(headers.size() > 0) { if(headers.size() > 0) {
for(std::map<coreutils::MString, coreutils::MString>::iterator header = headers.begin(); for(auto header = headers.begin();
header != headers.end(); header != headers.end();
++header) { ++header) {
std::cout << header->first << ": " << header->second << std::endl; std::cout << header->first << ": " << header->second << std::endl;

View File

@ -3,7 +3,6 @@
#include "MString.h" #include "MString.h"
#include <map> #include <map>
//#include <unordered_map>
namespace jet { namespace jet {

View File

@ -7,7 +7,7 @@ namespace jet {
Operand::Operand(coreutils::ZString &in) { Operand::Operand(coreutils::ZString &in) {
in.skipWhitespace(); in.skipWhitespace();
std::cout << "op: [" << in.unparsed() << "]" << std::endl;
if(in.ifNext("SUBSTRING")) { if(in.ifNext("SUBSTRING")) {
if(!in.ifNext("(")) if(!in.ifNext("("))
throw coreutils::Exception("Expecting ( for SUBSTRING parameters."); throw coreutils::Exception("Expecting ( for SUBSTRING parameters.");
@ -48,10 +48,9 @@ namespace jet {
boolean = false; boolean = false;
string = "false"; string = "false";
return; return;
} else if(in.startsWithDouble()) { } else if(in.startsWithNumber()) {
char *temp = in.getCursor();
doubleValue = in.asDouble(); doubleValue = in.asDouble();
string = coreutils::ZString(temp, in.getCursor() - temp); string = std::to_string(doubleValue);
return; return;
} else if(in.ifNext("'")) { } else if(in.ifNext("'")) {
string = in.getTokenExclude("'"); string = in.getTokenExclude("'");

View File

@ -1,7 +1,7 @@
#ifndef __Operand_h__ #ifndef __Operand_h__
#define __Operand_h__ #define __Operand_h__
#include "ZString.h" #include "MString.h"
namespace jet { namespace jet {
@ -19,7 +19,7 @@ namespace jet {
/// ///
bool boolean; bool boolean;
coreutils::ZString string; coreutils::MString string;
private: private:
// dataType enum ={}; // dataType enum ={};

View File

@ -7,7 +7,6 @@ namespace jet {
__set::__set(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { __set::__set(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) {
output = false; output = false;
processContainer(container);
if(!variableDefined("name")) if(!variableDefined("name"))
throw coreutils::Exception("set tag must have name defined."); throw coreutils::Exception("set tag must have name defined.");
if(!variableDefined("expr") && variableDefined("value") && hasContainer) if(!variableDefined("expr") && variableDefined("value") && hasContainer)
@ -24,6 +23,7 @@ namespace jet {
throw coreutils::Exception("Cannot use eval with expr."); throw coreutils::Exception("Cannot use eval with expr.");
global.variables[variables["name"]] = Expression(variables["expr"]).string; global.variables[variables["name"]] = Expression(variables["expr"]).string;
} else if(hasContainer) { } else if(hasContainer) {
processContainer(container);
if(evaluate) { if(evaluate) {
global.variables[variables["name"]] = out; global.variables[variables["name"]] = out;
} else { } else {

BIN
jet-2.0

Binary file not shown.

View File

@ -17,6 +17,7 @@ int main(int argc, char **argv) {
coreutils::MString out; coreutils::MString out;
jet::__jet *jet = new jet::__jet(data, out, global); jet::__jet *jet = new jet::__jet(data, out, global);
delete jet; delete jet;
global.dump();
std::cout << "----------------------" << std::endl; std::cout << "----------------------" << std::endl;
global.outputHeaders(); global.outputHeaders();
std::cout << out; std::cout << out;