Skip to content
Snippets Groups Projects
Commit fdbc4649 authored by Florian Pose's avatar Florian Pose
Browse files

Improved abbreviation.

parent 28dedc1f
No related branches found
No related tags found
No related merge requests found
...@@ -273,6 +273,13 @@ void Command::displayHelp() const ...@@ -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) bool abbrevMatch(const string &abb, const string &full)
{ {
unsigned int abbIndex; unsigned int abbIndex;
...@@ -294,13 +301,22 @@ list<const Command *> getMatchingCommands(const string &cmdStr) ...@@ -294,13 +301,22 @@ list<const Command *> getMatchingCommands(const string &cmdStr)
const Command *cmd; const Command *cmd;
list<const Command *> res; list<const Command *> res;
// find matching commands // find matching commands from beginning of the string
for (cmd = commands; cmd < cmdEnd; cmd++) { for (cmd = commands; cmd < cmdEnd; cmd++) {
if (abbrevMatch(cmdStr, cmd->name)) { if (substrMatch(cmdStr, cmd->name)) {
res.push_back(cmd); 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; return res;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment