1
0
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:
frosch
2025-04-02 16:18:41 +02:00
committed by frosch
parent f640daee4c
commit 20805ba84b
4 changed files with 10 additions and 13 deletions

View File

@@ -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;