Remove NOT_REACHED from Layouter::GetCharPosition

Return begin/end value for unknown code point index or out of range input

See: #596, #598, https://github.com/OpenTTD/OpenTTD/issues/11291
This commit is contained in:
Jonathan G Rennison
2023-09-26 17:27:24 +01:00
parent d4ed088498
commit aa4aee1d23

View File

@@ -230,10 +230,13 @@ Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const
const auto &line = this->front(); const auto &line = this->front();
/* Pointer to the end-of-string marker? Return total line width. */ /* Pointer to the end-of-string marker? Return total line width. */
if (ch == this->string.end()) { if (ch >= this->string.end()) {
Point p = { line->GetWidth(), 0 }; Point p = { line->GetWidth(), 0 };
return p; return p;
} }
if (ch < this->string.begin()) {
return { 0, 0 };
}
/* Find the code point index which corresponds to the char /* Find the code point index which corresponds to the char
* pointer into our UTF-8 source string. */ * pointer into our UTF-8 source string. */
@@ -264,7 +267,8 @@ Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const
} }
} }
NOT_REACHED(); /* Code point index not found, just give up */
return { 0, 0 };
} }
/** /**