From 42ead6b34dd5fa921bc2a160fd332cf77780afc1 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 25 Jun 2011 21:56:57 -0400 Subject: [PATCH] Report Filters - Report filters are now properly loaded and injected into the argument list. --- src/Arguments.cpp | 32 +++++++++++++++++++++++++++++++- src/Arguments.h | 1 + src/commands/CmdCustom.cpp | 7 +++++++ test/substitute.t | 10 ++++++++-- 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/Arguments.cpp b/src/Arguments.cpp index 1a0e1ee6d..a06f1a1ec 100644 --- a/src/Arguments.cpp +++ b/src/Arguments.cpp @@ -168,7 +168,7 @@ void Arguments::capture (int argc, const char** argv) } //////////////////////////////////////////////////////////////////////////////// -// Add a pair with a category of "". +// Append a pair with a category of "". void Arguments::capture (const std::string& arg) { std::vector parts; @@ -184,6 +184,36 @@ void Arguments::capture (const std::string& arg) categorize (); } +//////////////////////////////////////////////////////////////////////////////// +// Prepend a pair with a category of "". +void Arguments::capture_first (const std::string& arg) +{ + // Break the new argument into parts that comprise a series. + std::vector > series; + + std::vector parts; + if (is_multipart (arg, parts)) + { + std::vector ::iterator part; + for (part = parts.begin (); part != parts.end (); ++part) + series.push_back (std::make_pair (*part, "")); + } + else + series.push_back (std::make_pair (arg, "")); + + // Locate an appropriate place to insert the series. This would be + // immediately after the program and command arguments. + std::vector >::iterator position; + for (position = this->begin (); position != this->end (); ++position) + if (position->second != "program" && + position->second != "command") + break; + + this->insert (position, series.begin (), series.end ()); + + categorize (); +} + //////////////////////////////////////////////////////////////////////////////// // Add a pair for every word from std::cin, with a category of "". void Arguments::append_stdin () diff --git a/src/Arguments.h b/src/Arguments.h index f4437108e..b7e06239c 100644 --- a/src/Arguments.h +++ b/src/Arguments.h @@ -42,6 +42,7 @@ public: void capture (int, const char**); void capture (const std::string&); + void capture_first (const std::string&); void categorize (); void append_stdin (); diff --git a/src/commands/CmdCustom.cpp b/src/commands/CmdCustom.cpp index 8a4ded861..b48c162e7 100644 --- a/src/commands/CmdCustom.cpp +++ b/src/commands/CmdCustom.cpp @@ -82,6 +82,13 @@ int CmdCustom::execute (std::string& output) split (sortOrder, reportSort, ','); validateSortColumns (sortOrder); + // Prepend the argument list with those from the report filter. + std::vector filterArgs; + split (filterArgs, reportFilter, ' '); + std::vector ::iterator arg; + for (arg = filterArgs.begin (); arg != filterArgs.end (); ++ arg) + context.args.capture_first (*arg); + // Load the data. // TODO Replace with TDB2. std::vector tasks; diff --git a/test/substitute.t b/test/substitute.t index 0e0402633..13926e4d7 100755 --- a/test/substitute.t +++ b/test/substitute.t @@ -28,12 +28,13 @@ use strict; use warnings; -use Test::More tests => 11; +use Test::More tests => 12; # Create the rc file. if (open my $fh, '>', 'subst.rc') { - print $fh "data.location=.\n"; + print $fh "data.location=.\n", + "regex=off\n"; close $fh; ok (-r 'subst.rc', 'Created subst.rc'); } @@ -68,6 +69,11 @@ qx{../src/task rc:subst.rc 1 /bbb//}; $output = qx{../src/task rc:subst.rc info 1}; like ($output, qr/aaa ccc/, 'word deletion in description'); +# Regexes +qx{../src/task rc:subst.rc rc.regex:on 1 "/c(c)./C/"}; +$output = qx{../src/task rc:subst.rc info 1}; +like ($output, qr/aaa cCc/, 'regex'); + # Cleanup. unlink 'pending.data'; ok (!-r 'pending.data', 'Removed pending.data');