From 933c400922c55ade13f477c4d47bcaf45bfdf07a Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 24 Sep 2024 12:13:06 -0700 Subject: [PATCH] Variables work. Added trimline support. --- Global.cpp | 17 ++++++++++------- Global.h | 3 +-- KeywordValue.cpp | 6 ++---- Tag.cpp | 8 +++++++- testjet.cpp | 17 ++++++----------- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/Global.cpp b/Global.cpp index 51e158d..ebcb3c6 100644 --- a/Global.cpp +++ b/Global.cpp @@ -33,14 +33,15 @@ namespace jet { coreutils::ZString Global::getVariable(coreutils::ZString &variable) { if(variable.ifNext("$[")) { + coreutils::MString name; if(variable.ifNext("!")) { - return variables[renderVariableName(variable)]; + return variables[renderVariableName(name, variable)]; } if(variable.ifNext(":")) { // TODO: should only allow CGI variable name. Allow variable substitution. } if(variable.ifNext("@")) { // TODO: should only allow environment variables. Allow substitution. } else { - return variables[renderVariableName(variable)]; + return variables[renderVariableName(name, variable)]; } throw coreutils::Exception("expected variable name or type designator."); } if(variable.ifNext("#[")) { @@ -51,15 +52,17 @@ namespace jet { throw coreutils::Exception("Expecting a variable initializer ('$[' or '#[')."); } - coreutils::MString Global::renderVariableName(coreutils::ZString &variable) { - coreutils::MString name = variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"); + coreutils::MString Global::renderVariableName(coreutils::MString &name, coreutils::ZString &variable) { + name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"); if(variable.ifNext("]")) return name; if(variable.startsWith("$[")) { name << getVariable(variable); - return name; - } - return coreutils::MString(""); + if(variable.ifNext("]")) + return name; + } + renderVariableName(name, variable); + return name; } } diff --git a/Global.h b/Global.h index d89ec15..9c5bf86 100644 --- a/Global.h +++ b/Global.h @@ -19,12 +19,11 @@ namespace jet { void addSession(coreutils::MString sessionId, __mysql *mysql); void removeSession(coreutils::MString sessionId); coreutils::ZString getVariable(coreutils::ZString &variable); + coreutils::MString renderVariableName(coreutils::MString &name, coreutils::ZString &variable); std::map variables; std::map sessions; - private: - coreutils::MString renderVariableName(coreutils::ZString &variable); }; diff --git a/KeywordValue.cpp b/KeywordValue.cpp index 9b245eb..c4c21f5 100644 --- a/KeywordValue.cpp +++ b/KeywordValue.cpp @@ -5,10 +5,8 @@ namespace jet { KeywordValue::KeywordValue(coreutils::ZString data, Global &global) : MString() { while(!data.eod()) { - if(data.ifNext("$[")) { - coreutils::ZString varName(data.getTokenExclude("]")); - data.ifNext("]"); - write(global.variables[varName]); + if(data.startsWith("$[")) { + write(global.getVariable(data)); } else { write(data.charAt(0)); data.nextChar(); diff --git a/Tag.cpp b/Tag.cpp index 6dd662d..d6943f0 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -50,6 +50,9 @@ namespace jet { if(variableDefined("filterblanklines")) { filterBlankLines = variables["filterblanklines"] == "true" ? true: false; } + if(variableDefined("trimlines")) { + trimLines = variables["trimlines"] == "true" ? true: false; + } if(hasContainer) { coreutils::Log(coreutils::LOG_DEBUG_2) << "has Container: " << hasContainer; bool hasSplitTag = splitTagName == "" ? false: true; @@ -239,7 +242,10 @@ namespace jet { while(!in.eod()) { if(filterBlankLines) { if(!in.lineIsWhitespace()) { - out.write(in.goeol()); + if(trimLines) + out.write(in.goeol().trim()); + else + out.write(in.goeol()); out.write('\n'); } else { diff --git a/testjet.cpp b/testjet.cpp index 919614d..c79c707 100644 --- a/testjet.cpp +++ b/testjet.cpp @@ -6,7 +6,7 @@ int main(int argc, char **argv) { - coreutils::ZString data2("\n" + coreutils::ZString data("\n" " This is a comment and should not show up in the output.\n" " \n" " \n" @@ -20,7 +20,10 @@ int main(int argc, char **argv) { " another container value\n" " >>>$[noeval]<<<\n" " >>>$[thename]<<<\n" - " local: >>>#[name$[ix]]<<<\n" + " \n" + " \n" + " \n" + " $[test$[ix$[ix1]]$[iz]]\n" " \n" " \n" " 789\n" @@ -41,14 +44,6 @@ int main(int argc, char **argv) { " \n" "\n"); - coreutils::ZString data("\n" - " \n" - " \n" - " $[test$[ix]]\n" - "\n"); - -// coreutils::ZString data("ABCHIJXYZ\n"); - std::cout << "---------\n" << data << "----------\n" << std::endl; try { @@ -56,7 +51,7 @@ int main(int argc, char **argv) { coreutils::MString out; jet::__jet *jet = new jet::__jet(data, out, global); delete jet; - std::cout << ">>-------" << std::endl << out << std::endl << "<<------" << std::endl; + std::cout << ">>-------" << std::endl << out << "<<------" << std::endl; // global.dump(); } catch(coreutils::Exception e) {