Broken everything trying to get variable stuff situated.
This commit is contained in:
1 parent
4972799e7a
commit
062a023683
8 files changed
+51
-38
No files matched your search
+24
-21
@@ -37,24 +37,22 @@ namespace jet {
|
||||
sessions.erase(sessionId);
|
||||
}
|
||||
|
||||
coreutils::ZString Global::getVariable(coreutils::ZString &variable) {
|
||||
coreutils::ZString Global::getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &variables) {
|
||||
if(variable.ifNext("$[")) {
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
if(variable.ifNext("!")) {
|
||||
return variables[renderVariableName(variable, name, modifier)];
|
||||
renderVariableName(variable, name, modifier, variables);
|
||||
return variables[name];
|
||||
} if(variable.ifNext(":")) {
|
||||
// TODO: should only allow CGI variable name. Allow variable substitution.
|
||||
} if(variable.ifNext("@")) {
|
||||
// TODO: should only allow environment variables. Allow substitution.
|
||||
} if(variable.ifNext("$")) {
|
||||
return getenv(renderVariableName(variable, name, modifier).c_str());
|
||||
// TODO: should only allow session variables. Allow substitution.
|
||||
} if(variable.ifNext("%")) {
|
||||
renderVariableName(variable, name, modifier, variables);
|
||||
return getenv(name.c_str());
|
||||
} else {
|
||||
renderVariableName(variable, name, modifier);
|
||||
if(!variable.ifNext("]")) {
|
||||
std::cout << "unparsed: " << variable.unparsed() << std::endl;
|
||||
throw coreutils::Exception("expecting ] to close variable name.");
|
||||
}
|
||||
renderVariableName(variable, name, modifier, variables);
|
||||
name.split(".");
|
||||
if(name.getList().size() == 1)
|
||||
return variables[name[0]];
|
||||
@@ -69,18 +67,23 @@ namespace jet {
|
||||
throw coreutils::Exception("Expecting a variable initializer ('$[' or '#[').");
|
||||
}
|
||||
|
||||
coreutils::MString Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier) {
|
||||
name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
if(variable.ifNext("]"));
|
||||
else if(variable.ifNext(";")) {
|
||||
modifier = renderVariableName(variable, modifier, modifier);
|
||||
}
|
||||
else if(variable.startsWith("$[")) {
|
||||
name << getVariable(variable);
|
||||
}
|
||||
return name;
|
||||
void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &variables) {
|
||||
while(!variable.ifNext("]")) {
|
||||
name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
if(variable.ifNext(";")) {
|
||||
renderVariableName(variable, modifier, modifier, variables);
|
||||
return;
|
||||
}
|
||||
else if(variable.startsWith("$[")) {
|
||||
name << getVariable(variable, variables);
|
||||
}
|
||||
else if(variable.startsWith("#[")) {
|
||||
name << getVariable(variable, variables);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
__mysql * Global::getSession(coreutils::MString sessionId) {
|
||||
if(sessions.find(sessionId) == sessions.end())
|
||||
throw coreutils::Exception("requested session is not available.");
|
||||
|
||||
Reference in new issue
Block a user