Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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)
5 2008, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
14
21#include "include/logging.h"
22#include "lib/hash-standard.hpp"
23#include "lib/cmdline.hpp"
24#include "lib/format-util.hpp"
25
26#include <regex>
27
28using std::regex;
29using std::smatch;
30using std::regex_search;
31using util::join;
32using util::noneg;
33
34
35
36namespace lib {
37
38
41 Cmdline::Cmdline (int argc, const char** argv)
42 : vector<string> (noneg(argc-1))
43 {
44 for (int i=1; i<argc; ++i)
45 {
46 ASSERT (argv[i]);
47 (*this)[i-1] = argv[i];
48 }
49 }
50
51
55 Cmdline::Cmdline (const string cmdline)
56 {
57 static regex TOKENDEF{"\\S+"};
58 smatch match;
59 string::const_iterator it = cmdline.begin();
60 string::const_iterator end = cmdline.end();
61
62 while (regex_search(it, end, match, TOKENDEF))
63 {
64 string ss(match[0]);
65 this->push_back(ss);
66 it = match[0].second;
67 }
68
69 }
70
71
73 Cmdline::operator string () const
74 {
75 return join(*this," ");
76 }
77
78
79
80} // namespace lib
Class to encapsulate the typical C-style commandline definition.
Collection of small helpers and convenience shortcuts for diagnostics & formatting.
Helper to use a single extension point for specialised hash functions.
This header is for including and configuring NoBug.
Implementation namespace for support and library code.
constexpr NUM noneg(NUM val)
cut a numeric value to be >=0
Definition util.hpp:83
string join(COLL &&coll, string const &delim=", ")
enumerate a collection's contents, separated by delimiter.