We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 49034f3 commit 7aa0fdbCopy full SHA for 7aa0fdb
1 file changed
cpp2rust/converter/converter_lib.cpp
@@ -670,10 +670,13 @@ static std::string_view Trim(std::string_view s) {
670
}
671
672
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());
+ auto trimmed = Trim(s);
+ if (trimmed.starts_with(prefix) && trimmed.ends_with(suffix)) {
+ assert(trimmed.size() >= prefix.size() + suffix.size() &&
+ "prefix and suffix overlap in s");
677
+ trimmed.remove_prefix(prefix.size());
678
+ trimmed.remove_suffix(suffix.size());
679
+ s = std::string(trimmed);
680
681
682
0 commit comments