From 4c360c5a5951355426460f68ae560f9cf75cb395 Mon Sep 17 00:00:00 2001 From: Florian Pose Date: Tue, 22 Jul 2008 14:23:41 +0000 Subject: [PATCH] Improved abbreviation. --- tool/main.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tool/main.cpp b/tool/main.cpp index 6daafdf4..df525a00 100644 --- a/tool/main.cpp +++ b/tool/main.cpp @@ -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 getMatchingCommands(const string &cmdStr) const Command *cmd; list 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; }