Used std::string::front() and back() in more places
(cherry-picked from commit ed8a8a48f7
)
This commit is contained in:
parent
b7823147e5
commit
eb9a219c5f
8 changed files with 14 additions and 14 deletions
|
@ -87,8 +87,8 @@ struct config_implementation
|
|||
config->check_valid();
|
||||
|
||||
assert(!parent.empty());
|
||||
assert(parent[0] == '[');
|
||||
assert(parent[parent.size() - 1] == ']');
|
||||
assert(parent.front() == '[');
|
||||
assert(parent.back() == ']');
|
||||
|
||||
if(config->has_child(key)) {
|
||||
return *(config->children_.find(key)->second.front());
|
||||
|
|
|
@ -1183,7 +1183,7 @@ void binary_paths_manager::set_paths(const config& cfg)
|
|||
continue;
|
||||
}
|
||||
|
||||
if(!path.empty() && path[path.size() - 1] != '/')
|
||||
if(!path.empty() && path.back() != '/')
|
||||
path += "/";
|
||||
if(binary_paths.count(path) == 0) {
|
||||
binary_paths.insert(path);
|
||||
|
|
|
@ -1368,7 +1368,7 @@ formula_function_expression::formula_function_expression(const std::string& name
|
|||
, star_arg_(-1)
|
||||
{
|
||||
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);
|
||||
star_arg_ = n;
|
||||
break;
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ namespace preferences
|
|||
std::string name = preferences::get("login", EMPTY_LOGIN);
|
||||
if(name == EMPTY_LOGIN) {
|
||||
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);
|
||||
} else {
|
||||
ERR_CFG << "malformed user credentials (did you manually edit the preferences file?)" << std::endl;
|
||||
|
|
|
@ -258,7 +258,7 @@ static int intf_wml_matches_filter(lua_State* L)
|
|||
static int intf_log(lua_State *L) {
|
||||
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);
|
||||
if(msg.empty() || msg[msg.size() - 1] != '\n') {
|
||||
if(msg.empty() || msg.back() != '\n') {
|
||||
msg += '\n';
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
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;
|
||||
} else {
|
||||
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[set_total.size()-1] == '%') {
|
||||
if(set_total.back() == '%') {
|
||||
max_hit_points_ = lexical_cast_default<int>(set_total)*max_hit_points_/100;
|
||||
} else {
|
||||
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"];
|
||||
|
||||
if(!set.empty()) {
|
||||
if(set[set.size()-1] == '%') {
|
||||
if(set.back() == '%') {
|
||||
experience_ = lexical_cast_default<int>(set)*max_experience_/100;
|
||||
} else {
|
||||
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"];
|
||||
|
||||
if(set.empty() == false) {
|
||||
if(set[set.size()-1] == '%') {
|
||||
if(set.back() == '%') {
|
||||
max_experience_ = lexical_cast_default<int>(set)*max_experience_/100;
|
||||
} else {
|
||||
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_;
|
||||
|
||||
if(!set.empty()) {
|
||||
if(set[set.size()-1] == '%') {
|
||||
if(set.back() == '%') {
|
||||
recall_cost_ = lexical_cast_default<int>(set)*recall_cost/100;
|
||||
} else {
|
||||
recall_cost_ = lexical_cast_default<int>(set);
|
||||
|
|
|
@ -81,9 +81,9 @@ static std::u32string markov_generate_name(const markov_prefix_map& prefixes,
|
|||
}
|
||||
|
||||
res.resize(res.size()+1);
|
||||
res[res.size()-1] = c;
|
||||
res.back() = c;
|
||||
prefix.resize(prefix.size()+1);
|
||||
prefix[prefix.size()-1] = c;
|
||||
prefix.back() = c;
|
||||
while(prefix.size() > chain_size) {
|
||||
prefix.erase(prefix.begin());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue