本文整理汇总了C++中Chain::LinksLeft方法的典型用法代码示例。如果您正苦于以下问题:C++ Chain::LinksLeft方法的具体用法?C++ Chain::LinksLeft怎么用?C++ Chain::LinksLeft使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chain
的用法示例。
在下文中一共展示了Chain::LinksLeft方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: operator
std::string operator()(const std::vector<std::string> & argvec) {
if (argvec.size() != 4) {
return interp->RunCommand("help alias") + "\n(Please refer to the help documentation for proper invocation)";
}
// First get the alias name
std::string cmd = argvec[1];
std::vector<std::string> cmds;
// Next get the arguments.
Chain argSrc = argvec[2].c_str();
std::vector<std::string> args;
argSrc.SetDelimiters(",");
while(argSrc.LinksLeft()) {
args.push_back(argSrc.GetLink().c_str());
argSrc++;
}
Chain src = argvec[3].c_str();
src.SetDelimiters(",");
while(src.LinksLeft()) {
cmds.push_back(src.GetLink().c_str());
src++;
}
interp->AddCommand(cmd, new SubCommand(cmds, args, interp));
return std::string("Set new command: ") + cmd;
}
示例2: RunCommand
std::string Interpreter::RunCommand(const std::string & in_src) {
std::string in = in_src;
std::vector<std::string> args;
// compute any evaluator blocks in full
in = ReduceEvaluators(in_src);
Chain str = in;
std::string command = str.GetLink();
// the help keyword is special.
// if it is the first token in the command
// after evaluation, it will treat the following
// argument as the command to request help for
if (command == "help") {
str++;
std::string helpPage = str.GetLink();
auto helpCmd = commands.find(helpPage.c_str());
if (helpCmd == commands.end() || !helpPage.size()) {
Chain c = "";
if (helpPage.size())
c << "\"" << helpPage.c_str() << "\" does not exist as a command.\n";
c << "Here are the list of available commands:\n";
auto listIter = commands.begin();
while(listIter != commands.end()) {
c << " " << (listIter++)->first.c_str() << "\n";
}
return c;
}
return (Chain() << helpPage << ": " << helpCmd->second->Help() << "\n");
}
auto iter = commands.find(command.c_str());
if (iter == commands.end()) {
return (Chain() << "Unknown command \"" << in << "\"");
}
// parse arguments
while(str.LinksLeft()) {
if (str.GetLink()[0] != '"') {
// normal arg
args.push_back(str.GetLink().c_str()); str++;
} else {
// double quote arg
Chain compoundArg;
int iter = str.GetLinkPos();
iter++;
while(str.ToString()[iter] != '"' && iter < str.ToString().size()) {
compoundArg<<str.ToString()[iter];
iter++;
}
if (!(iter < str.ToString().size() &&
str.ToString()[iter] == '"' &&
iter != str.GetLinkPos())) {
return "Missing compound argument terminator \"...";
}
// push in arg minus quotes
args.push_back(compoundArg);
str = str.ToString().substr(iter+1, str.ToString().size()-1);
}
}
return (*(iter->second))(args);
}