Used std::string::front() and back() in more places

(cherry-picked from commit ed8a8a48f7)
This commit is contained in:
Charles Dang 2018-05-28 14:24:59 +11:00
parent b7823147e5
commit eb9a219c5f
8 changed files with 14 additions and 14 deletions

View file

@ -87,8 +87,8 @@ struct config_implementation
config->check_valid(); config->check_valid();
assert(!parent.empty()); assert(!parent.empty());
assert(parent[0] == '['); assert(parent.front() == '[');
assert(parent[parent.size() - 1] == ']'); assert(parent.back() == ']');
if(config->has_child(key)) { if(config->has_child(key)) {
return *(config->children_.find(key)->second.front()); return *(config->children_.find(key)->second.front());

View file

@ -1183,7 +1183,7 @@ void binary_paths_manager::set_paths(const config& cfg)
continue; continue;
} }
if(!path.empty() && path[path.size() - 1] != '/') if(!path.empty() && path.back() != '/')
path += "/"; path += "/";
if(binary_paths.count(path) == 0) { if(binary_paths.count(path) == 0) {
binary_paths.insert(path); binary_paths.insert(path);

View file

@ -1368,7 +1368,7 @@ formula_function_expression::formula_function_expression(const std::string& name
, star_arg_(-1) , star_arg_(-1)
{ {
for(std::size_t n = 0; n != arg_names_.size(); ++n) { for(std::size_t n = 0; n != arg_names_.size(); ++n) {
if(arg_names_.empty() == false && arg_names_[n][arg_names_[n].size() - 1] == '*') { if(arg_names_.empty() == false && arg_names_[n].back() == '*') {
arg_names_[n].resize(arg_names_[n].size() - 1); arg_names_[n].resize(arg_names_[n].size() - 1);
star_arg_ = n; star_arg_ = n;
break; break;

View file

@ -37,7 +37,7 @@ namespace
void strip_trailing_dir_separators(std::string& str) void strip_trailing_dir_separators(std::string& str)
{ {
while(filesystem::is_path_sep(str[str.size() - 1])) { while(filesystem::is_path_sep(str.back())) {
str.erase(str.size() - 1); str.erase(str.size() - 1);
} }
} }

View file

@ -109,7 +109,7 @@ namespace preferences
std::string name = preferences::get("login", EMPTY_LOGIN); std::string name = preferences::get("login", EMPTY_LOGIN);
if(name == EMPTY_LOGIN) { if(name == EMPTY_LOGIN) {
name = get_system_username(); name = get_system_username();
} else if(name.size() > 2 && name[0] == '@' && name[name.size() - 1] == '@') { } else if(name.size() > 2 && name.front() == '@' && name.back() == '@') {
name = name.substr(1, name.size() - 2); name = name.substr(1, name.size() - 2);
} else { } else {
ERR_CFG << "malformed user credentials (did you manually edit the preferences file?)" << std::endl; ERR_CFG << "malformed user credentials (did you manually edit the preferences file?)" << std::endl;

View file

@ -258,7 +258,7 @@ static int intf_wml_matches_filter(lua_State* L)
static int intf_log(lua_State *L) { static int intf_log(lua_State *L) {
const std::string& logger = lua_isstring(L, 2) ? luaL_checkstring(L, 1) : ""; const std::string& logger = lua_isstring(L, 2) ? luaL_checkstring(L, 1) : "";
std::string msg = lua_isstring(L, 2) ? luaL_checkstring(L, 2) : luaL_checkstring(L, 1); std::string msg = lua_isstring(L, 2) ? luaL_checkstring(L, 2) : luaL_checkstring(L, 1);
if(msg.empty() || msg[msg.size() - 1] != '\n') { if(msg.empty() || msg.back() != '\n') {
msg += '\n'; msg += '\n';
} }

View file

@ -1879,7 +1879,7 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
const bool violate_max = effect["violate_maximum"].to_bool(); const bool violate_max = effect["violate_maximum"].to_bool();
if(!set_hp.empty()) { if(!set_hp.empty()) {
if(set_hp[set_hp.size()-1] == '%') { if(set_hp.back() == '%') {
hit_points_ = lexical_cast_default<int>(set_hp)*max_hit_points_/100; hit_points_ = lexical_cast_default<int>(set_hp)*max_hit_points_/100;
} else { } else {
hit_points_ = lexical_cast_default<int>(set_hp); hit_points_ = lexical_cast_default<int>(set_hp);
@ -1887,7 +1887,7 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
} }
if(!set_total.empty()) { if(!set_total.empty()) {
if(set_total[set_total.size()-1] == '%') { if(set_total.back() == '%') {
max_hit_points_ = lexical_cast_default<int>(set_total)*max_hit_points_/100; max_hit_points_ = lexical_cast_default<int>(set_total)*max_hit_points_/100;
} else { } else {
max_hit_points_ = lexical_cast_default<int>(set_total); max_hit_points_ = lexical_cast_default<int>(set_total);
@ -1953,7 +1953,7 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
const std::string& set = effect["set"]; const std::string& set = effect["set"];
if(!set.empty()) { if(!set.empty()) {
if(set[set.size()-1] == '%') { if(set.back() == '%') {
experience_ = lexical_cast_default<int>(set)*max_experience_/100; experience_ = lexical_cast_default<int>(set)*max_experience_/100;
} else { } else {
experience_ = lexical_cast_default<int>(set); experience_ = lexical_cast_default<int>(set);
@ -1968,7 +1968,7 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
const std::string& set = effect["set"]; const std::string& set = effect["set"];
if(set.empty() == false) { if(set.empty() == false) {
if(set[set.size()-1] == '%') { if(set.back() == '%') {
max_experience_ = lexical_cast_default<int>(set)*max_experience_/100; max_experience_ = lexical_cast_default<int>(set)*max_experience_/100;
} else { } else {
max_experience_ = lexical_cast_default<int>(set); max_experience_ = lexical_cast_default<int>(set);
@ -2131,7 +2131,7 @@ void unit::apply_builtin_effect(std::string apply_to, const config& effect)
const int recall_cost = recall_cost_ < 0 ? resources::gameboard->teams().at(side_).recall_cost() : recall_cost_; const int recall_cost = recall_cost_ < 0 ? resources::gameboard->teams().at(side_).recall_cost() : recall_cost_;
if(!set.empty()) { if(!set.empty()) {
if(set[set.size()-1] == '%') { if(set.back() == '%') {
recall_cost_ = lexical_cast_default<int>(set)*recall_cost/100; recall_cost_ = lexical_cast_default<int>(set)*recall_cost/100;
} else { } else {
recall_cost_ = lexical_cast_default<int>(set); recall_cost_ = lexical_cast_default<int>(set);

View file

@ -81,9 +81,9 @@ static std::u32string markov_generate_name(const markov_prefix_map& prefixes,
} }
res.resize(res.size()+1); res.resize(res.size()+1);
res[res.size()-1] = c; res.back() = c;
prefix.resize(prefix.size()+1); prefix.resize(prefix.size()+1);
prefix[prefix.size()-1] = c; prefix.back() = c;
while(prefix.size() > chain_size) { while(prefix.size() > chain_size) {
prefix.erase(prefix.begin()); prefix.erase(prefix.begin());
} }