From efb84b20bf35e15ca76b93b9290e1850a602765e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 25 Oct 2014 22:46:56 -0400 Subject: [PATCH] CLI - Made ::canonicalize public. --- src/CLI.cpp | 74 ++++++++++++++++++++++++++--------------------------- src/CLI.h | 2 +- 2 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 5456b220e..bbbd33e75 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -403,6 +403,43 @@ const std::vector CLI::getModifications () return modifications; } +//////////////////////////////////////////////////////////////////////////////// +// Search for 'value' in _entities category, return canonicalized value. +bool CLI::canonicalize ( + std::string& canonicalized, + const std::string& category, + const std::string& value) const +{ + // Find the category. + std::pair ::const_iterator, std::multimap ::const_iterator> c; + c = _entities.equal_range (category); + + // Extract a list of entities for category. + std::vector options; + std::multimap ::const_iterator e; + for (e = c.first; e != c.second; ++e) + { + // Shortcut: if an exact match is found, success. + if (value == e->second) + { + canonicalized = value; + return true; + } + + options.push_back (e->second); + } + + // Match against the options, throw away results. + std::vector matches; + if (autoComplete (value, options, matches, minimumMatchLength) == 1) + { + canonicalized = matches[0]; + return true; + } + + return false; +} + //////////////////////////////////////////////////////////////////////////////// const std::string CLI::dump () const { @@ -596,43 +633,6 @@ bool CLI::exactMatch ( return false; } -//////////////////////////////////////////////////////////////////////////////// -// Search for 'value' in _entities category, return canonicalized value. -bool CLI::canonicalize ( - std::string& canonicalized, - const std::string& category, - const std::string& value) const -{ - // Find the category. - std::pair ::const_iterator, std::multimap ::const_iterator> c; - c = _entities.equal_range (category); - - // Extract a list of entities for category. - std::vector options; - std::multimap ::const_iterator e; - for (e = c.first; e != c.second; ++e) - { - // Shortcut: if an exact match is found, success. - if (value == e->second) - { - canonicalized = value; - return true; - } - - options.push_back (e->second); - } - - // Match against the options, throw away results. - std::vector matches; - if (autoComplete (value, options, matches, minimumMatchLength) == 1) - { - canonicalized = matches[0]; - return true; - } - - return false; -} - //////////////////////////////////////////////////////////////////////////////// // +tag --> tags _hastag_ tag // -tag --> tags _notag_ tag diff --git a/src/CLI.h b/src/CLI.h index 2ebadc31f..32a946394 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -73,6 +73,7 @@ public: const std::string getFilter (); const std::vector getWords (); const std::vector getModifications (); + bool canonicalize (std::string&, const std::string&, const std::string&) const; const std::string dump () const; private: @@ -80,7 +81,6 @@ private: void findOverrides (); void categorize (); bool exactMatch (const std::string&, const std::string&) const; - bool canonicalize (std::string&, const std::string&, const std::string&) const; void desugarTags (); void desugarAttributes (); void desugarAttributeModifiers ();