mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-17 17:32:45 +01:00
Codechange: Use EncodeUtf8 and DecodeUtf8 directly, when dealing with a single character.
This commit is contained in:
@@ -127,12 +127,10 @@ void Textbuf::DeleteAll()
|
||||
*/
|
||||
bool Textbuf::InsertChar(char32_t key)
|
||||
{
|
||||
uint16_t len = (uint16_t)Utf8CharLen(key);
|
||||
auto [src, len] = EncodeUtf8(key);
|
||||
if (this->buf.size() + len < this->max_bytes && this->chars + 1 <= this->max_chars) {
|
||||
/* Make space in the string, then overwrite it with the Utf8 encoded character. */
|
||||
auto pos = this->buf.begin() + this->caretpos;
|
||||
pos = this->buf.insert(pos, len, '\0');
|
||||
Utf8Encode(pos, key);
|
||||
this->buf.insert(this->caretpos, src, len);
|
||||
this->chars++;
|
||||
this->caretpos += len;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user