Lumiera  0.pre.03
»edityourfreedom«
cmdline.cpp
Go to the documentation of this file.
1 /*
2  Cmdline - abstraction of the usual commandline, a sequence of strings
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
30 #include "lib/util.hpp"
31 #include "include/logging.h"
32 #include "lib/cmdline.hpp"
33 
34 #include <boost/regex.hpp>
35 #include <boost/algorithm/string/join.hpp>
36 
37 using boost::regex;
38 using boost::smatch;
39 using boost::regex_search;
41 
42 using util::noneg;
43 
44 
45 
46 namespace lib {
47 
48 
51  Cmdline::Cmdline (int argc, const char** argv)
52  : vector<string> (noneg(argc-1))
53  {
54  for (int i=1; i<argc; ++i)
55  {
56  ASSERT (argv[i]);
57  (*this)[i-1] = argv[i];
58  }
59  }
60 
61 
65  Cmdline::Cmdline (const string cmdline)
66  {
67  regex tokendef("[^ \r\n\t]+");
68  smatch match;
69  string::const_iterator it = cmdline.begin();
70  string::const_iterator end = cmdline.end();
71 
72  while (regex_search(it, end, match, tokendef))
73  {
74  string ss(match[0]);
75  this->push_back(ss);
76  it = match[0].second;
77  }
78 
79  }
80 
81 
83  Cmdline::operator string () const
84  {
85  return join(*this," ");
86  }
87 
88 
89 
90 } // namespace lib
This header is for including and configuring NoBug.
string join(CON &&coll, string const &delim=", ")
enumerate a collection&#39;s contents, separated by delimiter.
Implementation namespace for support and library code.
Class to encapsulate the typical C-style commandline definition.
typename meta::Strip< CON >::TypeReferred::const_iterator const_iterator
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
NUM noneg(NUM val)
cut a numeric value to be >=0
Definition: util.hpp:78