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

Codechange: Use Utf8View to const-iterate over strings, if no particular error handling is needed.

This commit is contained in:
frosch
2025-04-02 16:16:14 +02:00
committed by frosch
parent 22ab0244d8
commit f06bfc0dad
5 changed files with 45 additions and 50 deletions

View File

@@ -587,15 +587,11 @@ static bool IsGarbageCharacter(char32_t c)
*/
static std::string_view SkipGarbage(std::string_view str)
{
auto first = std::begin(str);
auto last = std::end(str);
while (first < last) {
char32_t c;
size_t len = Utf8Decode(&c, &*first);
if (!IsGarbageCharacter(c)) break;
first += len;
}
return {first, last};
Utf8View view(str);
auto it = view.begin();
const auto end = view.end();
while (it != end && IsGarbageCharacter(*it)) ++it;
return str.substr(it.GetByteOffset());
}
/**