mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-19 03:39:20 +00:00
clearly check itor at end
cppcheck (via Codacy) notes that it's not clear that the iterator (j) cannot exceed end() because most don't expect pointer math. Rewrote to make it more clear what is going on.
This commit is contained in:
parent
59554ca0cd
commit
b74df558e0
@ -290,20 +290,18 @@ std::string encode_binary(const std::string& str)
|
||||
|
||||
std::string unencode_binary(const std::string& str)
|
||||
{
|
||||
std::string res;
|
||||
res.resize(str.size());
|
||||
std::string res(str.size(), '\0');
|
||||
|
||||
size_t n = 0;
|
||||
for(std::string::const_iterator j = str.begin(); j != str.end(); ++j) {
|
||||
if(*j == escape_char && j+1 != str.end()) {
|
||||
++j;
|
||||
res[n++] = *j - 1;
|
||||
res.resize(res.size()-1);
|
||||
} else {
|
||||
res[n++] = *j;
|
||||
for(std::string::const_iterator j = str.begin(); j != str.end(); ) {
|
||||
char c = *j++;
|
||||
if((c == escape_char) && (j != str.end())) {
|
||||
c = (*j++) - 1;
|
||||
}
|
||||
res[n++] = c;
|
||||
}
|
||||
|
||||
res.resize(n);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user