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:
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user