Skip to content

Commit

Permalink
shortcuts, return full string instead of copying it
Browse files Browse the repository at this point in the history
  • Loading branch information
arekbulski committed Apr 9, 2018
1 parent 231c279 commit 14b9bd8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion kaitai/kaitaistream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,15 @@ std::string kaitai::kstream::ensure_fixed_contents(std::string expected) {
}

std::string kaitai::kstream::bytes_strip_right(std::string src, char pad_byte) {
std::size_t new_len = src.length();
std::size_t max_len = src.length();
std::size_t new_len = max_len;

while (new_len > 0 && src[new_len - 1] == pad_byte)
new_len--;

if (new_len == max_len)
return src;

return src.substr(0, new_len);
}

Expand All @@ -417,6 +421,9 @@ std::string kaitai::kstream::bytes_terminate(std::string src, char term, bool in
if (include && new_len < max_len)
new_len++;

if (new_len == max_len)
return src;

return src.substr(0, new_len);
}

Expand Down

0 comments on commit 14b9bd8

Please sign in to comment.