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

Codechange: pass the characters to trim to StrTrimView

This commit is contained in:
Rubidium
2025-05-03 08:05:54 +02:00
committed by rubidium42
parent e2db8277b8
commit 1f39d469ff
8 changed files with 16 additions and 11 deletions

View File

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