MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / InsertChar

Method InsertChar

src/textbuf.cpp:128–144  ·  view source on GitHub ↗

* Insert a character to a textbuffer. If maxwidth of the Textbuf is zero, * we don't care about the visual-length but only about the physical * length of the string * @param key Character to be inserted * @return Return true on successful change of Textbuf, or false otherwise */

Source from the content-addressed store, hash-verified

126 * @return Return true on successful change of Textbuf, or false otherwise
127 */
128bool Textbuf::InsertChar(char32_t key)
129{
130 auto [src, len] = EncodeUtf8(key);
131 if (this->buf.size() + len < this->max_bytes && this->chars + 1 <= this->max_chars) {
132 /* Make space in the string, then overwrite it with the Utf8 encoded character. */
133 this->buf.insert(this->caretpos, src, len);
134 this->chars++;
135 this->caretpos += len;
136
137 this->UpdateStringIter();
138 this->UpdateWidth();
139 this->UpdateCaretPosition();
140 this->UpdateMarkedText();
141 return true;
142 }
143 return false;
144}
145
146/**
147 * Insert a string into the text buffer. If maxwidth of the Textbuf is zero,

Callers 2

HandleKeyPressMethod · 0.95
OnClickMethod · 0.80

Calls 7

UpdateStringIterMethod · 0.95
UpdateWidthMethod · 0.95
UpdateCaretPositionMethod · 0.95
UpdateMarkedTextMethod · 0.95
EncodeUtf8Function · 0.85
sizeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected