From c2f8c81a887c508988aa6cb19a38db3106bd23e2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 15 Oct 2014 00:02:45 -0400 Subject: [PATCH] CLI - Implemented ::unsweetenTags, which resolves the syntactic sugar to an expression. --- src/CLI.cpp | 31 +++++++++++++++++++++++++++++++ src/CLI.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/CLI.cpp b/src/CLI.cpp index 0e08c339e..ba896584f 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -307,6 +308,36 @@ bool CLI::canonicalize ( return false; } +//////////////////////////////////////////////////////////////////////////////// +// +tag --> tags _hastag_ tag +// -tag --> tags _notag_ tag +void CLI::unsweetenTags () +{ + std::vector reconstructed; + + std::vector ::iterator i; + for (i = _filter.begin (); i != _filter.end (); ++i) + { + Nibbler n (*i); + std::string tag; + std::string sign; + + if (n.getN (1, sign) && + (sign == "+" || sign == "-") && + n.getUntilEOS (tag) && + tag.find (' ') == std::string::npos) + { + reconstructed.push_back ("tags"); + reconstructed.push_back (sign == "+" ? "_hastag_" : "_notag_"); + reconstructed.push_back (tag); + } + else + reconstructed.push_back (*i); + } + + _filter = reconstructed; +} + //////////////////////////////////////////////////////////////////////////////// void CLI::dump (const std::string& label) const { diff --git a/src/CLI.h b/src/CLI.h index a61aa4144..35828c7ee 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -49,6 +49,7 @@ private: void categorize (); bool exactMatch (const std::string&, const std::string&) const; bool canonicalize (std::string&, const std::string&, const std::string&) const; + void unsweetenTags (); void dump (const std::string&) const; public: