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

Method Assign

src/textbuf.cpp:420–437  ·  view source on GitHub ↗

* Copy a string into the textbuffer. * @param text Source. */

Source from the content-addressed store, hash-verified

418 * @param text Source.
419 */
420void Textbuf::Assign(std::string_view text)
421{
422 size_t bytes = std::min<size_t>(this->max_bytes - 1, text.size());
423 this->buf = StrMakeValid(text.substr(0, bytes));
424
425 /* Make sure the name isn't too long for the text buffer in the number of
426 * characters (not bytes). max_chars also counts the '\0' characters. */
427 Utf8View view(text);
428 auto it = view.begin();
429 const auto end = view.end();
430 for (size_t len = 1; len < this->max_chars && it != end; ++len) ++it;
431
432 if (it != end) {
433 this->buf.erase(it.GetByteOffset(), std::string::npos);
434 }
435
436 this->UpdateSize();
437}
438
439
440/**

Callers 15

UpdateSignEditWindowMethod · 0.45
GenerateFileNameMethod · 0.45
SaveLoadWindowMethod · 0.45
OnClickMethod · 0.45
ApplySuggestionMethod · 0.45
IConsoleHistoryNavigateFunction · 0.45
SavePresetWindowMethod · 0.45
OnClickMethod · 0.45
OnClickMethod · 0.45
RandomTownNameMethod · 0.45
QueryStringWindowMethod · 0.45
AutoCompleteMethod · 0.45

Calls 8

UpdateSizeMethod · 0.95
substrMethod · 0.80
GetByteOffsetMethod · 0.80
StrMakeValidFunction · 0.70
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected