From 7a544489aef4f4071efed1d6a6f5e01d830b74ae Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 6 Jul 2011 22:47:47 -0400 Subject: [PATCH] Command Line - Added a method for extracting unstructured text from the command line. --- src/Arguments.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++ src/Arguments.h | 1 + 2 files changed, 57 insertions(+) diff --git a/src/Arguments.cpp b/src/Arguments.cpp index 5494e1d0b..aa020cc33 100644 --- a/src/Arguments.cpp +++ b/src/Arguments.cpp @@ -1502,6 +1502,62 @@ Arguments Arguments::extract_modifications () return modifications; } +//////////////////////////////////////////////////////////////////////////////// +Arguments Arguments::extract_simple_words () +{ + Arguments filter; + + std::vector ::iterator arg; + for (arg = this->begin (); arg != this->end (); ++arg) + { + // Excluded. + if (arg->_third == "program" || + arg->_third == "command" || + arg->_third == "rc" || + arg->_third == "override" || + arg->_third == "attr" || + arg->_third == "attmod") + { + ; + } + + // Included. + else if (arg->_third == "tag" || + arg->_third == "pattern" || + arg->_third == "seq" || + arg->_third == "op" || + arg->_third == "exp" || + arg->_third == "word") + { + // "limit" is special - it is recognized but not included in filters. + if (arg->_first.find ("limit:") == std::string::npos) + filter.push_back (*arg); + } + + // Error. + else + { + if (arg->_third == "tag") + throw std::string ("A tag '") + arg->_first + "' is not allowed " + "with this command."; + + else if (arg->_third == "pattern") + throw std::string ("A pattern '") + arg->_first + "' is not allowed " + "with this command."; + + else if (arg->_third == "substitution") + throw std::string ("A substitution '") + arg->_first + "' is not allowed " + "with this command."; + + else + throw std::string ("Argument '") + arg->_first + "' is not allowed " + "with this command."; + } + } + + return filter; +} + //////////////////////////////////////////////////////////////////////////////// bool Arguments::valid_modifier (const std::string& modifier) { diff --git a/src/Arguments.h b/src/Arguments.h index 1730ec5ea..5b6506b39 100644 --- a/src/Arguments.h +++ b/src/Arguments.h @@ -132,6 +132,7 @@ public: Arguments extract_read_only_filter (); Arguments extract_write_filter (); Arguments extract_modifications (); + Arguments extract_simple_words (); static bool valid_modifier (const std::string&);