From aef3155784f11d2a7238f314049228e46080374e Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Thu, 20 Dec 2007 12:52:20 -0800 Subject: convert macro command parsing to use new StringUtil function --- src/FbTk/LogicCommands.cc | 56 +++++++++++++++++++---------------------------- src/FbTk/MacroCommand.cc | 26 ++++++++++------------ 2 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/FbTk/LogicCommands.cc b/src/FbTk/LogicCommands.cc index df5f2d5..f9e8ab7 100644 --- a/src/FbTk/LogicCommands.cc +++ b/src/FbTk/LogicCommands.cc @@ -26,6 +26,8 @@ #include "ObjectRegistry.hh" #include "StringUtil.hh" +#include + using FbTk::StringUtil::removeFirstWhitespace; using FbTk::StringUtil::toLower; using std::string; @@ -36,20 +38,16 @@ namespace { template M *addCommands(M *macro, const string &args, bool trusted) { - int pos = 0, err = 0; - string cmd; - - while (true) { - RefCount tmp(0); - err = StringUtil::getStringBetween(cmd, args.c_str() + pos, - '{', '}', " \t\n", true); - pos += err; - if (err == 0) - break; - - tmp = ObjectRegistry::instance().parse(cmd, trusted); - if (*tmp) - macro->add(tmp); + std::string blah; + std::vector cmds; + StringUtil::stringTokensBetween(cmds, args, blah, '{', '}'); + RefCount cmd(0); + + std::vector::iterator it = cmds.begin(), it_end = cmds.end(); + for (; it != it_end; ++it) { + cmd = ObjectRegistry::instance().parse(*it, trusted); + if (*cmd) + macro->add(cmd); } if (macro->size() > 0) @@ -85,31 +83,23 @@ REGISTER_OBJECT_PARSER(xor, parseLogicCommand, BoolCommand); Command *IfCommand::parse(const std::string &command, const std::string &args, bool trusted) { - std::string cmd; - int err = 0, pos = 0; + std::string blah; + std::vector cmds; RefCount cond(0); RefCount t(0), f(0); - err = StringUtil::getStringBetween(cmd, args.c_str(), - '{', '}', " \t\n", true); - if (err > 0) - cond = ObjectRegistry::instance().parse(cmd, trusted); - if (err == 0 || *cond == 0) + StringUtil::stringTokensBetween(cmds, args, blah, '{', '}'); + if (cmds.size() < 3) return 0; - pos = err; - err = StringUtil::getStringBetween(cmd, args.c_str() + pos, - '{', '}', " \t\n", true); - if (err == 0) + cond = ObjectRegistry::instance().parse(cmds[0], trusted); + if (*cond == 0) return 0; - t = ObjectRegistry::instance().parse(cmd, trusted); - - pos += err; - err = StringUtil::getStringBetween(cmd, args.c_str() + pos, - '{', '}', " \t\n", true); - if (err > 0) - f = ObjectRegistry::instance().parse(cmd, trusted); - if (err == 0 || *t == 0 && *f == 0) + + t = ObjectRegistry::instance().parse(cmds[1], trusted); + if (cmds.size() >= 3) + f = ObjectRegistry::instance().parse(cmds[2], trusted); + if (*t == 0 && *f == 0) return 0; return new IfCommand(cond, t, f); diff --git a/src/FbTk/MacroCommand.cc b/src/FbTk/MacroCommand.cc index 55d403c..3a05179 100644 --- a/src/FbTk/MacroCommand.cc +++ b/src/FbTk/MacroCommand.cc @@ -26,6 +26,7 @@ #include "ObjectRegistry.hh" #include "StringUtil.hh" +#include #include namespace FbTk { @@ -35,21 +36,16 @@ namespace { template M *addCommands(M *macro, const std::string &args, bool trusted) { - std::string cmd; - int err = 0; - int pos = 0; - - while (true) { - RefCount next(0); - pos += err; - err = StringUtil::getStringBetween(cmd, args.c_str() + pos, - '{', '}', " \t\n", true); - if (err == 0) - break; - if (err > 0) - next = ObjectRegistry::instance().parse(cmd, trusted); - if (*next != 0) - macro->add(next); + std::string blah; + std::list cmds; + StringUtil::stringTokensBetween(cmds, args, blah, '{', '}'); + RefCount cmd(0); + + std::list::iterator it = cmds.begin(), it_end = cmds.end(); + for (; it != it_end; ++it) { + cmd = ObjectRegistry::instance().parse(*it, trusted); + if (*cmd) + macro->add(cmd); } if (macro->size() > 0) -- cgit v0.11.2