Improved abbreviation.

This commit is contained in:
Florian Pose 2008-07-22 14:23:41 +00:00
parent d103d9295d
commit 4c360c5a59
1 changed files with 18 additions and 2 deletions

View File

@ -273,6 +273,13 @@ void Command::displayHelp() const
/****************************************************************************/
bool substrMatch(const string &abb, const string &full)
{
return full.substr(0, abb.length()) == abb;
}
/****************************************************************************/
bool abbrevMatch(const string &abb, const string &full)
{
unsigned int abbIndex;
@ -294,13 +301,22 @@ list<const Command *> getMatchingCommands(const string &cmdStr)
const Command *cmd;
list<const Command *> res;
// find matching commands
// find matching commands from beginning of the string
for (cmd = commands; cmd < cmdEnd; cmd++) {
if (abbrevMatch(cmdStr, cmd->name)) {
if (substrMatch(cmdStr, cmd->name)) {
res.push_back(cmd);
}
}
if (!res.size()) { // nothing found
// find /any/ matching commands
for (cmd = commands; cmd < cmdEnd; cmd++) {
if (abbrevMatch(cmdStr, cmd->name)) {
res.push_back(cmd);
}
}
}
return res;
}