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