Commit 1ee22ec9ffc2875cee864ce10e05747b102b8f16

Authored by Henry Fredrick Schreiner
1 parent 60934c8a

Using empty instead of 0 size

.clang-tidy
1 #Checks: '*,-clang-analyzer-alpha.*' 1 #Checks: '*,-clang-analyzer-alpha.*'
2 #Checks: '-*,google-readability-casting,llvm-namespace-comment,performance-unnecessary-value-param,llvm-include-order,misc-throw-by-value-catch-by-reference,readability-container-size-empty,google-runtime-references,modernize*' 2 #Checks: '-*,google-readability-casting,llvm-namespace-comment,performance-unnecessary-value-param,llvm-include-order,misc-throw-by-value-catch-by-reference,readability-container-size-empty,google-runtime-references,modernize*'
3 -Checks: '-*,llvm-namespace-comment,llvm-include-order' 3 +Checks: '-*,llvm-namespace-comment,llvm-include-order,readability-container-size-empty'
4 HeaderFilterRegex: '.*hpp' 4 HeaderFilterRegex: '.*hpp'
5 CheckOptions: 5 CheckOptions:
6 - key: readability-braces-around-statements.ShortStatementLines 6 - key: readability-braces-around-statements.ShortStatementLines
include/CLI/App.hpp
@@ -602,7 +602,7 @@ public: @@ -602,7 +602,7 @@ public:
602 for(const Option_p &opt : options_) { 602 for(const Option_p &opt : options_) {
603 603
604 // Only process option with a long-name 604 // Only process option with a long-name
605 - if(opt->lnames_.size() > 0) { 605 + if(!opt->lnames_.empty()) {
606 std::string name = prefix + opt->lnames_[0]; 606 std::string name = prefix + opt->lnames_[0];
607 607
608 // Non-flags 608 // Non-flags
@@ -644,7 +644,7 @@ public: @@ -644,7 +644,7 @@ public:
644 prev += " " + name_; 644 prev += " " + name_;
645 645
646 auto selected_subcommands = get_subcommands(); 646 auto selected_subcommands = get_subcommands();
647 - if(selected_subcommands.size() > 0) 647 + if(!selected_subcommands.empty())
648 return selected_subcommands.at(0)->help(wid, prev); 648 return selected_subcommands.at(0)->help(wid, prev);
649 649
650 std::stringstream out; 650 std::stringstream out;
@@ -676,7 +676,7 @@ public: @@ -676,7 +676,7 @@ public:
676 pos=true; 676 pos=true;
677 } 677 }
678 678
679 - if(subcommands_.size() > 0) { 679 + if(!subcommands_.empty()) {
680 if(require_subcommand_ != 0) 680 if(require_subcommand_ != 0)
681 out << " SUBCOMMAND"; 681 out << " SUBCOMMAND";
682 else 682 else
@@ -715,7 +715,7 @@ public: @@ -715,7 +715,7 @@ public:
715 } 715 }
716 716
717 // Subcommands 717 // Subcommands
718 - if(subcommands_.size()> 0) { 718 + if(!subcommands_.empty()) {
719 out << "Subcommands:" << std::endl; 719 out << "Subcommands:" << std::endl;
720 for(const App_p &com : subcommands_) 720 for(const App_p &com : subcommands_)
721 detail::format_help(out, com->get_name(), com->description_, wid); 721 detail::format_help(out, com->get_name(), com->description_, wid);
@@ -829,7 +829,7 @@ protected: @@ -829,7 +829,7 @@ protected:
829 parsed_ = true; 829 parsed_ = true;
830 bool positional_only = false; 830 bool positional_only = false;
831 831
832 - while(args.size()>0) { 832 + while(!args.empty()) {
833 _parse_single(args, positional_only); 833 _parse_single(args, positional_only);
834 } 834 }
835 835
@@ -842,7 +842,7 @@ protected: @@ -842,7 +842,7 @@ protected:
842 if (config_ptr_ != nullptr && config_name_ != "") { 842 if (config_ptr_ != nullptr && config_name_ != "") {
843 try { 843 try {
844 std::vector<detail::ini_ret_t> values = detail::parse_ini(config_name_); 844 std::vector<detail::ini_ret_t> values = detail::parse_ini(config_name_);
845 - while(values.size() > 0) { 845 + while(!values.empty()) {
846 if(!_parse_ini(values)) { 846 if(!_parse_ini(values)) {
847 throw ExtrasINIError(values.back().fullname); 847 throw ExtrasINIError(values.back().fullname);
848 } 848 }
@@ -888,7 +888,7 @@ protected: @@ -888,7 +888,7 @@ protected:
888 } 888 }
889 889
890 auto selected_subcommands =get_subcommands(); 890 auto selected_subcommands =get_subcommands();
891 - if(require_subcommand_ < 0 && selected_subcommands.size() == 0) 891 + if(require_subcommand_ < 0 && selected_subcommands.empty())
892 throw RequiredError("Subcommand required"); 892 throw RequiredError("Subcommand required");
893 else if(require_subcommand_ > 0 && static_cast<int>( selected_subcommands.size()) != require_subcommand_) 893 else if(require_subcommand_ > 0 && static_cast<int>( selected_subcommands.size()) != require_subcommand_)
894 throw RequiredError(std::to_string(require_subcommand_) + " subcommand(s) required"); 894 throw RequiredError(std::to_string(require_subcommand_) + " subcommand(s) required");
@@ -1081,11 +1081,11 @@ protected: @@ -1081,11 +1081,11 @@ protected:
1081 1081
1082 1082
1083 if(num == -1) { 1083 if(num == -1) {
1084 - while(args.size()>0 && _recognize(args.back()) == detail::Classifer::NONE) { 1084 + while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) {
1085 op->add_result(args.back()); 1085 op->add_result(args.back());
1086 args.pop_back(); 1086 args.pop_back();
1087 } 1087 }
1088 - } else while(num>0 && args.size() > 0) { 1088 + } else while(num>0 && !args.empty()) {
1089 num--; 1089 num--;
1090 std::string current_ = args.back(); 1090 std::string current_ = args.back();
1091 args.pop_back(); 1091 args.pop_back();
@@ -1137,11 +1137,11 @@ protected: @@ -1137,11 +1137,11 @@ protected:
1137 } 1137 }
1138 1138
1139 if(num == -1) { 1139 if(num == -1) {
1140 - while(args.size() > 0 && _recognize(args.back()) == detail::Classifer::NONE) { 1140 + while(!args.empty() && _recognize(args.back()) == detail::Classifer::NONE) {
1141 op->add_result(args.back()); 1141 op->add_result(args.back());
1142 args.pop_back(); 1142 args.pop_back();
1143 } 1143 }
1144 - } else while(num>0 && args.size()>0) { 1144 + } else while(num>0 && !args.empty()) {
1145 num--; 1145 num--;
1146 op->add_result(args.back()); 1146 op->add_result(args.back());
1147 args.pop_back(); 1147 args.pop_back();
include/CLI/Option.hpp
@@ -354,12 +354,12 @@ public: @@ -354,12 +354,12 @@ public:
354 } 354 }
355 if(envname_ != "") 355 if(envname_ != "")
356 out << " (env:" << envname_ << ")"; 356 out << " (env:" << envname_ << ")";
357 - if(requires_.size() > 0) { 357 + if(!requires_.empty()) {
358 out << " Requires:"; 358 out << " Requires:";
359 for(const Option* opt : requires_) 359 for(const Option* opt : requires_)
360 out << " " << opt->get_name(); 360 out << " " << opt->get_name();
361 } 361 }
362 - if(excludes_.size() > 0) { 362 + if(!excludes_.empty()) {
363 out << " Excludes:"; 363 out << " Excludes:";
364 for(const Option* opt : excludes_) 364 for(const Option* opt : excludes_)
365 out << " " << opt->get_name(); 365 out << " " << opt->get_name();
@@ -377,7 +377,7 @@ public: @@ -377,7 +377,7 @@ public:
377 void run_callback() const { 377 void run_callback() const {
378 if(!callback_(results_)) 378 if(!callback_(results_))
379 throw ConversionError(get_name() + "=" + detail::join(results_)); 379 throw ConversionError(get_name() + "=" + detail::join(results_));
380 - if(validators_.size()>0) { 380 + if(!validators_.empty()) {
381 for(const std::string & result : results_) 381 for(const std::string & result : results_)
382 for(const std::function<bool(std::string)> &vali : validators_) 382 for(const std::function<bool(std::string)> &vali : validators_)
383 if(!vali(result)) 383 if(!vali(result))
@@ -486,7 +486,7 @@ public: @@ -486,7 +486,7 @@ public:
486 ///@{ 486 ///@{
487 /// Can print positional name detailed option if true 487 /// Can print positional name detailed option if true
488 bool _has_help_positional() const { 488 bool _has_help_positional() const {
489 - return get_positional() && (has_description() || requires_.size()>0 || excludes_.size()>0 ); 489 + return get_positional() && (has_description() || !requires_.empty() || !excludes_.empty() );
490 } 490 }
491 ///@} 491 ///@}
492 }; 492 };
include/CLI/StringTools.hpp
@@ -136,7 +136,7 @@ bool valid_later_char(T c) { @@ -136,7 +136,7 @@ bool valid_later_char(T c) {
136 136
137 /// Verify an option name 137 /// Verify an option name
138 inline bool valid_name_string(const std::string &str) { 138 inline bool valid_name_string(const std::string &str) {
139 - if(str.size()<1 || !valid_first_char(str[0])) 139 + if(str.empty() || !valid_first_char(str[0]))
140 return false; 140 return false;
141 for(auto c : str.substr(1)) 141 for(auto c : str.substr(1))
142 if(!valid_later_char(c)) 142 if(!valid_later_char(c))
@@ -160,7 +160,7 @@ inline std::vector&lt;std::string&gt; split_up(std::string str) { @@ -160,7 +160,7 @@ inline std::vector&lt;std::string&gt; split_up(std::string str) {
160 160
161 std::vector<std::string> output; 161 std::vector<std::string> output;
162 162
163 - while(str.size() > 0) { 163 + while(!str.empty()) {
164 if(str[0] == '\'') { 164 if(str[0] == '\'') {
165 auto end = str.find('\'', 1); 165 auto end = str.find('\'', 1);
166 if(end != std::string::npos) { 166 if(end != std::string::npos) {