Use !std::string::empty() for string-is-not-empty comparisons

This commit is contained in:
Charles Dang 2017-09-05 05:43:41 +11:00
parent 23e68633da
commit 2eacb4e1c3
25 changed files with 45 additions and 45 deletions

View file

@ -266,12 +266,12 @@ void arrow::update_symbols()
}
image_filename = dirname + style_ + "/" + prefix;
if (suffix != "")
if (!suffix.empty())
{
image_filename += ("-" + suffix);
}
image_filename += ".png";
assert(image_filename != "");
assert(!image_filename.empty());
image::locator image = image::locator(image_filename, mods);
if (!image.file_exists())

View file

@ -1624,7 +1624,7 @@ void display::set_diagnostic(const std::string& msg)
diagnostic_label_ = 0;
}
if(msg != "") {
if(!msg.empty()) {
font::floating_label flabel(msg);
flabel.set_font_size(font::SIZE_PLUS);
flabel.set_color(font::YELLOW_COLOR);

View file

@ -113,7 +113,7 @@ namespace gui{
label_string_ = label;
mode_ = mode;
if(check_label != "") {
if(!check_label.empty()) {
check_.reset(new gui::button(gui.video(),check_label,gui::button::TYPE_CHECK));
check_->set_check(checked);
}

View file

@ -392,7 +392,7 @@ void create_engine::prepare_for_campaign(const std::string& difficulty)
{
DBG_MP << "preparing data for campaign by reloading game config\n";
if(difficulty != "") {
if(!difficulty.empty()) {
state_.classification().difficulty = difficulty;
} else if(!selected_campaign_difficulty_.empty()) {
state_.classification().difficulty = selected_campaign_difficulty_;

View file

@ -850,7 +850,7 @@ bool game_launcher::play_multiplayer(mp_selection res)
} catch (mapgen_exception& e) {
gui2::show_error_message(video(), _("Map generator error: ") + e.message);
} catch(wesnothd_error& e) {
if(e.message != "") {
if(!e.message.empty()) {
ERR_NET << "caught network error: " << e.message << std::endl;
gui2::show_transient_message(video()
, ""
@ -859,7 +859,7 @@ bool game_launcher::play_multiplayer(mp_selection res)
ERR_NET << "caught network error" << std::endl;
}
} catch(config::error& e) {
if(e.message != "") {
if(!e.message.empty()) {
ERR_CONFIG << "caught config::error: " << e.message << std::endl;
gui2::show_transient_message(video(), "", e.message);
} else {

View file

@ -308,7 +308,7 @@ double passage_path_calculator::cost(const map_location& loc, const double) cons
void cave_map_generator::cave_map_generator_job::place_passage(const passage& p)
{
const std::string& chance = p.cfg["chance"];
if(chance != "" && int(rng_()%100) < std::stoi(chance)) {
if(!chance.empty() && int(rng_()%100) < std::stoi(chance)) {
return;
}

View file

@ -168,7 +168,7 @@ namespace {
to(t_translation::GRASS_LAND)
{
const std::string& terrain = cfg["terrain"];
if(terrain != "") {
if(!terrain.empty()) {
to = t_translation::read_terrain_code(terrain);
}
}
@ -207,7 +207,7 @@ namespace {
, to(t_translation::NONE_TERRAIN)
{
const std::string& to_str = cfg["to"];
if(to_str != "") {
if(!to_str.empty()) {
to = t_translation::read_terrain_code(to_str);
}
}
@ -1116,7 +1116,7 @@ std::string default_map_generator_job::default_generate_map(generator_data data,
terrain[x][y] = letter;
if(misc_labels != nullptr) {
const map_location loc(x - data.width / 3, y - data.height / 3); //add to use for village naming
if(road_base_name != "")
if(!road_base_name.empty())
road_names.emplace(loc, road_base_name);
}
}

View file

@ -95,7 +95,7 @@ void campaign_selection::campaign_selected(window& window)
}
assert(tree.selected_item());
if(tree.selected_item()->id() != "") {
if(!tree.selected_item()->id().empty()) {
auto iter = std::find(page_ids_.begin(), page_ids_.end(), tree.selected_item()->id());
const int choice = iter - page_ids_.begin();
if(iter == page_ids_.end()) {
@ -296,7 +296,7 @@ void campaign_selection::post_show(window& window)
}
assert(tree.selected_item());
if(tree.selected_item()->id() != "") {
if(!tree.selected_item()->id().empty()) {
auto iter = std::find(page_ids_.begin(), page_ids_.end(), tree.selected_item()->id());
if(iter != page_ids_.end()) {
choice_ = iter - page_ids_.begin();

View file

@ -206,7 +206,7 @@ void show_help(CVideo& video, const section &toplevel_sec,
hb.set_location(xloc + left_padding, yloc + top_padding);
hb.set_width(width - left_padding - right_padding);
hb.set_height(height - top_padding - bot_padding);
if (show_topic != "") {
if (!show_topic.empty()) {
hb.show_topic(show_topic);
}
else {

View file

@ -145,7 +145,7 @@ void help_browser::handle_event(const SDL_Event &event)
const int mousex = mouse_event.x;
const int mousey = mouse_event.y;
const std::string ref = text_area_.ref_at(mousex, mousey);
if (ref != "") {
if (!ref.empty()) {
const topic *t = find_topic(toplevel_, ref);
if (t == nullptr) {
std::stringstream msg;
@ -170,7 +170,7 @@ void help_browser::update_cursor()
int mousex, mousey;
SDL_GetMouseState(&mousex,&mousey);
const std::string ref = text_area_.ref_at(mousex, mousey);
if (ref != "" && !ref_cursor_) {
if (!ref.empty() && !ref_cursor_) {
cursor::set(cursor::HYPERLINK);
ref_cursor_ = true;
}

View file

@ -1245,7 +1245,7 @@ std::vector<std::string> parse_text(const std::string &text)
msg << "Element '" << ss.str() << "' continues through end of string.";
throw parse_error(msg.str());
}
if (ss.str() != "") {
if (!ss.str().empty()) {
// Add the last string.
res.push_back(ss.str());
}
@ -1289,7 +1289,7 @@ std::string convert_to_wml(const std::string &element_name, const std::string &c
msg << "Unterminated single quote after: '" << ss.str() << "'";
throw parse_error(msg.str());
}
if (ss.str() != "") {
if (!ss.str().empty()) {
attributes.push_back(ss.str());
}
ss.str("");
@ -1407,7 +1407,7 @@ void generate_contents()
// toplevel. Hence, add it to the hidden ones if it
// is not referenced from another section.
if (!section_is_referenced(id, *help_config)) {
if (ss.str() != "") {
if (!ss.str().empty()) {
ss << ",";
}
ss << id;
@ -1421,7 +1421,7 @@ void generate_contents()
const std::string id = topic["id"];
if (find_topic(default_toplevel, id) == nullptr) {
if (!topic_is_referenced(id, *help_config)) {
if (ss.str() != "") {
if (!ss.str().empty()) {
ss << ",";
}
ss << id;

View file

@ -116,7 +116,7 @@ void help_text_area::set_items()
std::vector<std::string> const &parsed_items = shown_topic_->text.parsed_text();
std::vector<std::string>::const_iterator it;
for (it = parsed_items.begin(); it != parsed_items.end(); ++it) {
if (*it != "" && (*it)[0] == '[') {
if (!(*it).empty() && (*it)[0] == '[') {
// Should be parsed as WML.
try {
config cfg;
@ -247,7 +247,7 @@ void help_text_area::handle_jump_cfg(const config &cfg)
throw parse_error("Jump markup must have either a to or an amount attribute.");
}
unsigned jump_to = curr_loc_.first;
if (amount_str != "") {
if (!amount_str.empty()) {
unsigned amount;
try {
amount = lexical_cast<unsigned, std::string>(amount_str);
@ -257,7 +257,7 @@ void help_text_area::handle_jump_cfg(const config &cfg)
}
jump_to += amount;
}
if (to_str != "") {
if (!to_str.empty()) {
unsigned to;
try {
to = lexical_cast<unsigned, std::string>(to_str);
@ -577,7 +577,7 @@ std::string help_text_area::ref_at(const int x, const int y)
const std::list<item>::const_iterator it =
std::find_if(items_.begin(), items_.end(), item_at(local_x, cmp_y));
if (it != items_.end()) {
if ((*it).ref_to != "") {
if (!(*it).ref_to.empty()) {
return ((*it).ref_to);
}
}

View file

@ -264,7 +264,7 @@ public:
*/
virtual bool valid() const
{
return keycode_ != SDLK_UNKNOWN && text_ != "";
return keycode_ != SDLK_UNKNOWN && !text_.empty();
}
protected:

View file

@ -118,7 +118,7 @@ const terrain_label* map_labels::get_label(const map_location& loc) const
// No such team label. Try to find global label, except if that's what we just did.
// NOTE: This also avoid infinite recursion
if(res == nullptr && team_name() != "") {
if(res == nullptr && !team_name().empty()) {
return get_label(loc, "");
}

View file

@ -155,7 +155,7 @@ void playsingle_controller::play_scenario_init()
saved_game_.replay_start() = to_config();
}
start_game();
if( saved_game_.classification().random_mode != "" && is_networked_mp()) {
if(!saved_game_.classification().random_mode.empty() && is_networked_mp()) {
// This won't cause errors later but we should notify the user about it in case he didn't knew it.
gui2::show_transient_message(
gui_->video(),

View file

@ -309,9 +309,9 @@ void saved_game::expand_mp_events()
boost::copy( mp_settings_.active_mods
| boost::adaptors::transformed(modevents_entry_for("modification"))
, std::back_inserter(mods) );
if(mp_settings_.mp_era != "") //We don't want the error message below if there is no era (= if this is a sp game)
if(!mp_settings_.mp_era.empty()) //We don't want the error message below if there is no era (= if this is a sp game)
{ mods.emplace_back("era", mp_settings_.mp_era); }
if(classification_.campaign != "")
if(!classification_.campaign.empty())
{ mods.emplace_back("campaign", classification_.campaign); }
// In the first iteration mod contains no [resource]s in all other iterations, mods contains only [resource]s

View file

@ -597,7 +597,7 @@ std::string si_string(double input, bool base2, const std::string& unit) {
si_string_impl_stream_write(ss, input);
ss << ' '
<< *prefix
<< (base2 && (*prefix != "") ? _("infix_binary^i") : "")
<< (base2 && (!(*prefix).empty()) ? _("infix_binary^i") : "")
<< unit;
return ss.str();
}

View file

@ -915,7 +915,7 @@ bool game::process_turn(simple_wml::document& data, const socket_ptr user) {
marked.push_back(index - marked.size());
} else if ((**command).child("speak")) {
simple_wml::node& speak = *(**command).child("speak");
if (speak["to_sides"] != "" || is_muted_observer(user)) {
if (!speak["to_sides"].empty() || is_muted_observer(user)) {
DBG_GAME << "repackaging..." << std::endl;
repackage = true;
}

View file

@ -814,7 +814,7 @@ void server::add_player(socket_ptr socket, const wesnothd::player& player)
send_to_player(socket, games_and_users_list_);
if (motd_ != "") {
if (!motd_.empty()) {
send_server_message(socket, motd_);
}
@ -2599,7 +2599,7 @@ void server::motd_handler(const std::string& /*issuer_name*/, const std::string&
assert(out != NULL);
if (parameters == "") {
if (motd_ != "") {
if (!motd_.empty()) {
*out << "Message of the day:\n" << motd_;
return;
} else {

View file

@ -151,11 +151,11 @@ BOOST_AUTO_TEST_CASE ( test_config_attribute_value )
// blank != "" test.
c = config();
BOOST_CHECK(cc["x"] != "");
BOOST_CHECK(!cc["x"].empty());
BOOST_CHECK(cc["x"].empty());
BOOST_CHECK(cc["x"].blank());
BOOST_CHECK(c["x"] != "");
BOOST_CHECK(!c["x"].empty());
BOOST_CHECK(c["x"].empty());
BOOST_CHECK(c["x"].blank());

View file

@ -89,23 +89,23 @@ struct animation_cursor
const std::string s_branch_value = branch.attributes["value"];
const std::string s_branch_value_2nd = branch.attributes["value_second"];
if(s_branch_hits != "" && s_branch_hits == s_cfg_hits) {
if(!s_branch_hits.empty() && s_branch_hits == s_cfg_hits) {
previously_hits_set = true;
}
if(s_branch_direction != "" && s_branch_direction == s_cfg_direction) {
if(!s_branch_direction.empty() && s_branch_direction == s_cfg_direction) {
previously_direction_set = true;
}
if(s_branch_terrain != "" && s_branch_terrain == s_cfg_terrain) {
if(!s_branch_terrain.empty() && s_branch_terrain == s_cfg_terrain) {
previously_terrain_set = true;
}
if(s_branch_value != "" && s_branch_value == s_cfg_value) {
if(!s_branch_value.empty() && s_branch_value == s_cfg_value) {
previously_value_set = true;
}
if(s_branch_value_2nd != "" && s_branch_value_2nd == s_cfg_value_2nd) {
if(!s_branch_value_2nd.empty() && s_branch_value_2nd == s_cfg_value_2nd) {
previously_value_2nd_set = true;
}
}

View file

@ -65,7 +65,7 @@ attack_type::attack_type(const config& cfg) :
description_ = translation::egettext(id_.c_str());
if(icon_.empty()){
if (id_ != "")
if (!id_.empty())
icon_ = "attacks/" + id_ + ".png";
else
icon_ = "attacks/blank-attack.png";

View file

@ -391,7 +391,7 @@ void unit_type::build_created(
}
const std::string& advances_to_val = cfg_["advances_to"];
if(advances_to_val != "null" && advances_to_val != "") {
if(advances_to_val != "null" && !advances_to_val.empty()) {
advances_to_ = utils::split(advances_to_val);
}

View file

@ -515,7 +515,7 @@ unit::unit(const config& cfg, bool use_traits, const vconfig* vcfg)
std::vector<std::string> temp_advances = utils::split(cfg["advances_to"]);
if(temp_advances.size() == 1 && temp_advances.front() == "null") {
advances_to_.clear();
} else if(temp_advances.size() >= 1 && temp_advances.front() != "") {
} else if(temp_advances.size() >= 1 && !temp_advances.front().empty()) {
advances_to_ = temp_advances;
}
@ -1759,7 +1759,7 @@ std::string unit::describe_builtin_effect(std::string apply_to, const config& ef
std::string desc;
for(attack_ptr a : attacks_) {
bool affected = a->describe_modification(effect, &desc);
if(affected && desc != "") {
if(affected && !desc.empty()) {
attack_names.emplace_back(a->name(), "wesnoth-units");
}
}

View file

@ -317,7 +317,7 @@ void widget::set_tooltip_string(const std::string& str)
void widget::process_help_string(int mousex, int mousey)
{
if (!hidden() && sdl::point_in_rect(mousex, mousey, rect_)) {
if(help_string_ == 0 && help_text_ != "") {
if(help_string_ == 0 && !help_text_.empty()) {
//std::cerr << "setting help string to '" << help_text_ << "'\n";
help_string_ = video().set_help_string(help_text_);
}