Functional variable retrieval including #[local].

This commit is contained in:
Brad Arant committed 2024-10-17 15:57:35 -07:00
1 parent 062a023683
commit f0b3c0e0f6
4 files changed
+15 -14

No files matched your search

+12 -11
View File
@@ -37,22 +37,22 @@ namespace jet {
sessions.erase(sessionId);
}
coreutils::ZString Global::getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &variables) {
coreutils::ZString Global::getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &lvariables) {
if(variable.ifNext("$[")) {
coreutils::MString name;
coreutils::MString modifier;
if(variable.ifNext("!")) {
renderVariableName(variable, name, modifier, variables);
renderVariableName(variable, name, modifier, lvariables);
return variables[name];
} if(variable.ifNext(":")) {
// TODO: should only allow CGI variable name. Allow variable substitution.
} if(variable.ifNext("@")) {
// TODO: should only allow session variables. Allow substitution.
} if(variable.ifNext("%")) {
renderVariableName(variable, name, modifier, variables);
renderVariableName(variable, name, modifier, lvariables);
return getenv(name.c_str());
} else {
renderVariableName(variable, name, modifier, variables);
renderVariableName(variable, name, modifier, lvariables);
name.split(".");
if(name.getList().size() == 1)
return variables[name[0]];
@@ -60,25 +60,26 @@ namespace jet {
}
throw coreutils::Exception("expected variable name or type designator.");
} if(variable.ifNext("#[")) {
// TODO: this local variable type has no special naming conventions. We
// just need to do nested variable substitution for the entry.
coreutils::MString name;
coreutils::MString modifier;
renderVariableName(variable, name, modifier, lvariables);
return lvariables[name];
}
throw coreutils::Exception("Expecting a variable initializer ('$[' or '#[').");
}
void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &variables) {
void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &lvariables) {
while(!variable.ifNext("]")) {
name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
if(variable.ifNext(";")) {
renderVariableName(variable, modifier, modifier, variables);
renderVariableName(variable, modifier, modifier, lvariables);
return;
}
else if(variable.startsWith("$[")) {
name << getVariable(variable, variables);
name << getVariable(variable, lvariables);
}
else if(variable.startsWith("#[")) {
name << getVariable(variable, variables);
name << getVariable(variable, lvariables);
}
}
return;