Skip to content

Commit 7aa0fdb

Browse files
committed
Move overlapping check in assert
1 parent 49034f3 commit 7aa0fdb

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

cpp2rust/converter/converter_lib.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,13 @@ static std::string_view Trim(std::string_view s) {
670670
}
671671

672672
void Unwrap(std::string &s, std::string_view prefix, std::string_view suffix) {
673-
Trim(s);
674-
if (s.size() >= prefix.size() + suffix.size() && s.starts_with(prefix) &&
675-
s.ends_with(suffix)) {
676-
s = s.substr(prefix.size(), s.size() - prefix.size() - suffix.size());
673+
auto trimmed = Trim(s);
674+
if (trimmed.starts_with(prefix) && trimmed.ends_with(suffix)) {
675+
assert(trimmed.size() >= prefix.size() + suffix.size() &&
676+
"prefix and suffix overlap in s");
677+
trimmed.remove_prefix(prefix.size());
678+
trimmed.remove_suffix(suffix.size());
679+
s = std::string(trimmed);
677680
}
678681
}
679682

0 commit comments

Comments
 (0)