From 1abda3900bb12893c2f0fef5ffb2102e8689b7ff Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 21 Feb 2015 15:45:38 +0100 Subject: [PATCH] CLI: Abstract adding new raw filter to a new helper method --- src/CLI.cpp | 14 ++++++++++++++ src/CLI.h | 1 + src/commands/CmdCustom.cpp | 10 +--------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/CLI.cpp b/src/CLI.cpp index 5177a0e7c..240a07d9f 100644 --- a/src/CLI.cpp +++ b/src/CLI.cpp @@ -374,6 +374,20 @@ void CLI::add (const std::string& arg) analyze (); } +//////////////////////////////////////////////////////////////////////////////// +// Process raw string into parsed filter. +// +void CLI::addRawFilter (const std::string& arg) +{ + std::string lexeme; + Lexer::Type type; + Lexer lex (arg); + lex.ambiguity (false); + + while (lex.token (lexeme, type)) + add (lexeme); +} + //////////////////////////////////////////////////////////////////////////////// // Intended to be called after ::initialize() and ::add(), to perform the final // analysis. Analysis is also performed directly after the above, because there diff --git a/src/CLI.h b/src/CLI.h index e855db697..c3aa0e692 100644 --- a/src/CLI.h +++ b/src/CLI.h @@ -77,6 +77,7 @@ public: void entity (const std::string&, const std::string&); void initialize (int, const char**); void add (const std::string&); + void addRawFilter (const std::string& arg); void analyze (bool parse = true, bool strict = false); void applyOverrides (); const std::string getFilter (); diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index 1876dab23..4bcd46e4c 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -82,15 +82,7 @@ int CmdCustom::execute (std::string& output) validateSortColumns (sortOrder); // Prepend the argument list with those from the report filter. - std::string lexeme; - Lexer::Type type; - Lexer lex (reportFilter); - lex.ambiguity (false); - while (lex.token (lexeme, type)) - context.cli.add (lexeme); - - // Reparse after tree change. - context.cli.analyze (); + context.cli.addRawFilter(reportFilter); // Apply filter. handleRecurrence ();