1
1
/* ****************************************************************************
2
2
* ___ _ _ ___ ___
3
3
* | _|| | | | | _ \ _ \ CLIPP - command line interfaces for modern C++
4
- * | |_ | |_ | | | _/ _/ version 1.2.0
4
+ * | |_ | |_ | | | _/ _/ version 1.2.1
5
5
* |___||___||_| |_| |_| https://github.com/muellan/clipp
6
6
*
7
7
* Licensed under the MIT License <http://opensource.org/licenses/MIT>.
@@ -114,12 +114,12 @@ class subrange {
114
114
115
115
/* * @brief returns true, if query string is a prefix of the subject string */
116
116
constexpr bool prefix () const noexcept {
117
- return at_ == 0 && length_ > 0 ;
117
+ return at_ == 0 ;
118
118
}
119
119
120
120
/* * @brief returns true, if query is a substring of the query string */
121
121
constexpr explicit operator bool () const noexcept {
122
- return at_ != arg_string::npos && length_ > 0 ;
122
+ return at_ != arg_string::npos;
123
123
}
124
124
125
125
private:
@@ -605,8 +605,7 @@ class map_arg_to
605
605
map_arg_to (T& target) noexcept : t_{std::addressof (target)} {}
606
606
607
607
void operator () (const char * s) const {
608
- if (t_ && s && (std::strlen (s) > 0 ))
609
- *t_ = detail::make<T>::from (s);
608
+ if (t_ && s) *t_ = detail::make<T>::from (s);
610
609
}
611
610
612
611
private:
@@ -914,6 +913,7 @@ inline subrange
914
913
substring_match (const std::basic_string<C,T,A>& subject,
915
914
const std::basic_string<C,T,A>& query)
916
915
{
916
+ if (subject.empty () && query.empty ()) return subrange (0 ,0 );
917
917
if (subject.empty () || query.empty ()) return subrange{};
918
918
auto i = subject.find (query);
919
919
if (i == std::basic_string<C,T,A>::npos) return subrange{};
@@ -2014,12 +2014,13 @@ class parameter :
2014
2014
subrange
2015
2015
match (const arg_string& arg) const
2016
2016
{
2017
- if (arg.empty ()) return subrange{};
2018
-
2019
2017
if (flags_.empty ()) {
2020
2018
return matcher_ (arg);
2021
2019
}
2022
2020
else {
2021
+ // empty flags are not allowed
2022
+ if (arg.empty ()) return subrange{};
2023
+
2023
2024
if (std::find (flags_.begin (), flags_.end (), arg) != flags_.end ()) {
2024
2025
return subrange{0 ,arg.size ()};
2025
2026
}
@@ -4337,7 +4338,7 @@ class match_t {
4337
4338
const arg_string& str () const noexcept { return str_; }
4338
4339
const scoped_dfs_traverser& pos () const noexcept { return pos_; }
4339
4340
4340
- explicit operator bool () const noexcept { return !str_. empty ( ); }
4341
+ explicit operator bool () const noexcept { return bool (pos_ ); }
4341
4342
4342
4343
private:
4343
4344
arg_string str_;
@@ -4357,8 +4358,6 @@ match_t
4357
4358
full_match (scoped_dfs_traverser pos, const arg_string& arg,
4358
4359
const ParamSelector& select)
4359
4360
{
4360
- if (arg.empty ()) return match_t {};
4361
-
4362
4361
while (pos) {
4363
4362
if (pos->is_param ()) {
4364
4363
const auto & param = pos->as_param ();
@@ -4388,8 +4387,6 @@ match_t
4388
4387
prefix_match (scoped_dfs_traverser pos, const arg_string& arg,
4389
4388
const ParamSelector& select)
4390
4389
{
4391
- if (arg.empty ()) return match_t {};
4392
-
4393
4390
while (pos) {
4394
4391
if (pos->is_param ()) {
4395
4392
const auto & param = pos->as_param ();
@@ -4424,8 +4421,6 @@ match_t
4424
4421
partial_match (scoped_dfs_traverser pos, const arg_string& arg,
4425
4422
const ParamSelector& select)
4426
4423
{
4427
- if (arg.empty ()) return match_t {};
4428
-
4429
4424
while (pos) {
4430
4425
if (pos->is_param ()) {
4431
4426
const auto & param = pos->as_param ();
@@ -4581,7 +4576,7 @@ class parser
4581
4576
++eaten_;
4582
4577
++index_;
4583
4578
4584
- if (!valid () || arg. empty () ) return false ;
4579
+ if (!valid ()) return false ;
4585
4580
4586
4581
if (!blocked_ && try_match (arg)) return true ;
4587
4582
@@ -4856,7 +4851,7 @@ class parser
4856
4851
void add_match (const match_t & match)
4857
4852
{
4858
4853
const auto & pos = match.pos ();
4859
- if (!pos || !pos->is_param () || match. str (). empty () ) return ;
4854
+ if (!pos || !pos->is_param ()) return ;
4860
4855
4861
4856
pos_.next_after_match (pos);
4862
4857
@@ -5256,7 +5251,7 @@ parse(std::initializer_list<const char*> arglist, const group& cli)
5256
5251
arg_list args;
5257
5252
args.reserve (arglist.size ());
5258
5253
for (auto a : arglist) {
5259
- if ( std::strlen (a) > 0 ) args.push_back (a);
5254
+ args.push_back (a);
5260
5255
}
5261
5256
5262
5257
return parse (std::move (args), cli);
@@ -6924,7 +6919,8 @@ void print(OStream& os, const parsing_result& result)
6924
6919
template <class OStream >
6925
6920
void print (OStream& os, const parameter& p)
6926
6921
{
6927
- if (p.blocking ()) os << ' !' ;
6922
+ if (p.greedy ()) os << ' !' ;
6923
+ if (p.blocking ()) os << ' ~' ;
6928
6924
if (!p.required ()) os << ' [' ;
6929
6925
os << doc_label (p);
6930
6926
if (p.repeatable ()) os << " ..." ;
0 commit comments