1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-16 00:42:45 +01:00

Codefix: implement StrTrimInPlace without assigning a borrowed view of itself

This commit is contained in:
Rubidium
2025-05-03 07:49:14 +02:00
committed by rubidium42
parent 4109b6848b
commit e2db8277b8
2 changed files with 10 additions and 3 deletions

View File

@@ -225,7 +225,15 @@ bool StrValid(std::span<const char> str)
*/
void StrTrimInPlace(std::string &str)
{
str = StrTrimView(str);
size_t first_pos = str.find_first_not_of(' ');
if (first_pos == std::string::npos) {
str.clear();
return;
}
str.erase(0, first_pos);
size_t last_pos = str.find_last_not_of(' ');
str.erase(last_pos + 1);
}
std::string_view StrTrimView(std::string_view str)