Commit 79aaa8b8d7559ef8e011526f6d50b0562ea91058

Authored by Henry Fredrick Schreiner
Committed by Henry Schreiner
1 parent 8cdf1c86

Adding tidy suggestions, mostly empty() fixes

include/CLI/App.hpp
@@ -552,7 +552,7 @@ class App { @@ -552,7 +552,7 @@ class App {
552 remove_option(config_ptr_); 552 remove_option(config_ptr_);
553 config_name_ = default_filename; 553 config_name_ = default_filename;
554 config_required_ = required; 554 config_required_ = required;
555 - config_ptr_ = add_option(name, config_name_, help, default_filename != ""); 555 + config_ptr_ = add_option(name, config_name_, help, !default_filename.empty());
556 return config_ptr_; 556 return config_ptr_;
557 } 557 }
558 558
@@ -716,7 +716,7 @@ class App { @@ -716,7 +716,7 @@ class App {
716 out << name << "=" << detail::inijoin(opt->results()) << std::endl; 716 out << name << "=" << detail::inijoin(opt->results()) << std::endl;
717 717
718 // If the option has a default and is requested by optional argument 718 // If the option has a default and is requested by optional argument
719 - else if(default_also && opt->defaultval_ != "") 719 + else if(default_also && !opt->defaultval_.empty())
720 out << name << "=" << opt->defaultval_ << std::endl; 720 out << name << "=" << opt->defaultval_ << std::endl;
721 // Flag, one passed 721 // Flag, one passed
722 } else if(opt->count() == 1) { 722 } else if(opt->count() == 1) {
@@ -740,7 +740,7 @@ class App { @@ -740,7 +740,7 @@ class App {
740 /// Makes a help message, with a column wid for column 1 740 /// Makes a help message, with a column wid for column 1
741 std::string help(size_t wid = 30, std::string prev = "") const { 741 std::string help(size_t wid = 30, std::string prev = "") const {
742 // Delegate to subcommand if needed 742 // Delegate to subcommand if needed
743 - if(prev == "") 743 + if(prev.empty())
744 prev = name_; 744 prev = name_;
745 else 745 else
746 prev += " " + name_; 746 prev += " " + name_;
@@ -931,7 +931,7 @@ class App { @@ -931,7 +931,7 @@ class App {
931 config_ptr_->run_callback(); 931 config_ptr_->run_callback();
932 config_required_ = true; 932 config_required_ = true;
933 } 933 }
934 - if(config_name_ != "") { 934 + if(!config_name_.empty()) {
935 try { 935 try {
936 std::vector<detail::ini_ret_t> values = detail::parse_ini(config_name_); 936 std::vector<detail::ini_ret_t> values = detail::parse_ini(config_name_);
937 while(!values.empty()) { 937 while(!values.empty()) {
@@ -948,7 +948,7 @@ class App { @@ -948,7 +948,7 @@ class App {
948 948
949 // Get envname options if not yet passed 949 // Get envname options if not yet passed
950 for(const Option_p &opt : options_) { 950 for(const Option_p &opt : options_) {
951 - if(opt->count() == 0 && opt->envname_ != "") { 951 + if(opt->count() == 0 && !opt->envname_.empty()) {
952 char *buffer = nullptr; 952 char *buffer = nullptr;
953 std::string ename_string; 953 std::string ename_string;
954 954
@@ -1029,7 +1029,7 @@ class App { @@ -1029,7 +1029,7 @@ class App {
1029 std::string name = current.name(); 1029 std::string name = current.name();
1030 1030
1031 // If a parent is listed, go to a subcommand 1031 // If a parent is listed, go to a subcommand
1032 - if(parent != "") { 1032 + if(!parent.empty()) {
1033 current.level++; 1033 current.level++;
1034 for(const App_p &com : subcommands_) 1034 for(const App_p &com : subcommands_)
1035 if(com->check_name(parent)) 1035 if(com->check_name(parent))
@@ -1200,7 +1200,7 @@ class App { @@ -1200,7 +1200,7 @@ class App {
1200 if(num == 0) { 1200 if(num == 0) {
1201 op->add_result(""); 1201 op->add_result("");
1202 parse_order_.push_back(op.get()); 1202 parse_order_.push_back(op.get());
1203 - } else if(rest != "") { 1203 + } else if(!rest.empty()) {
1204 if(num > 0) 1204 if(num > 0)
1205 num--; 1205 num--;
1206 op->add_result(rest); 1206 op->add_result(rest);
@@ -1223,7 +1223,7 @@ class App { @@ -1223,7 +1223,7 @@ class App {
1223 parse_order_.push_back(op.get()); 1223 parse_order_.push_back(op.get());
1224 } 1224 }
1225 1225
1226 - if(rest != "") { 1226 + if(!rest.empty()) {
1227 rest = "-" + rest; 1227 rest = "-" + rest;
1228 args.push_back(rest); 1228 args.push_back(rest);
1229 } 1229 }
@@ -1261,7 +1261,7 @@ class App { @@ -1261,7 +1261,7 @@ class App {
1261 1261
1262 int num = op->get_expected(); 1262 int num = op->get_expected();
1263 1263
1264 - if(value != "") { 1264 + if(!value.empty()) {
1265 if(num != -1) 1265 if(num != -1)
1266 num--; 1266 num--;
1267 op->add_result(value); 1267 op->add_result(value);
include/CLI/Option.hpp
@@ -310,16 +310,16 @@ class Option { @@ -310,16 +310,16 @@ class Option {
310 std::stringstream out; 310 std::stringstream out;
311 311
312 if(get_expected() != 0) { 312 if(get_expected() != 0) {
313 - if(typeval_ != "") 313 + if(!typeval_.empty())
314 out << " " << typeval_; 314 out << " " << typeval_;
315 - if(defaultval_ != "") 315 + if(!defaultval_.empty())
316 out << "=" << defaultval_; 316 out << "=" << defaultval_;
317 if(get_expected() > 1) 317 if(get_expected() > 1)
318 out << " x " << get_expected(); 318 out << " x " << get_expected();
319 if(get_expected() == -1) 319 if(get_expected() == -1)
320 out << " ..."; 320 out << " ...";
321 } 321 }
322 - if(envname_ != "") 322 + if(!envname_.empty())
323 out << " (env:" << envname_ << ")"; 323 out << " (env:" << envname_ << ")";
324 if(!requires_.empty()) { 324 if(!requires_.empty()) {
325 out << " Requires:"; 325 out << " Requires:";
include/CLI/StringTools.hpp
@@ -18,7 +18,7 @@ namespace detail { @@ -18,7 +18,7 @@ namespace detail {
18 inline std::vector<std::string> split(const std::string &s, char delim) { 18 inline std::vector<std::string> split(const std::string &s, char delim) {
19 std::vector<std::string> elems; 19 std::vector<std::string> elems;
20 // Check to see if emtpy string, give consistent result 20 // Check to see if emtpy string, give consistent result
21 - if(s == "") 21 + if(s.empty())
22 elems.emplace_back(""); 22 elems.emplace_back("");
23 else { 23 else {
24 std::stringstream ss; 24 std::stringstream ss;
@@ -106,7 +106,7 @@ inline std::string trim_copy(const std::string &amp;str, const std::string &amp;filter) @@ -106,7 +106,7 @@ inline std::string trim_copy(const std::string &amp;str, const std::string &amp;filter)
106 inline void format_help(std::stringstream &out, std::string name, std::string description, size_t wid) { 106 inline void format_help(std::stringstream &out, std::string name, std::string description, size_t wid) {
107 name = " " + name; 107 name = " " + name;
108 out << std::setw(static_cast<int>(wid)) << std::left << name; 108 out << std::setw(static_cast<int>(wid)) << std::left << name;
109 - if(description != "") { 109 + if(!description.empty()) {
110 if(name.length() >= wid) 110 if(name.length() >= wid)
111 out << std::endl << std::setw(static_cast<int>(wid)) << ""; 111 out << std::endl << std::setw(static_cast<int>(wid)) << "";
112 out << description; 112 out << description;