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

Method LoadText

src/textfile_gui.cpp:907–930  ·  view source on GitHub ↗

* Load a text into the textfile viewer. * * This will split the text into newlines and stores it for fast drawing. * * @param buf The text to load. */

Source from the content-addressed store, hash-verified

905 * @param buf The text to load.
906 */
907void TextfileWindow::LoadText(std::string_view buf)
908{
909 std::string text = StrMakeValid(buf, {StringValidationSetting::ReplaceWithQuestionMark, StringValidationSetting::AllowNewline, StringValidationSetting::ReplaceTabCrNlWithSpace});
910 this->lines.clear();
911
912 /* Split the string on newlines. */
913 std::string_view p(text);
914 auto next = p.find_first_of('\n');
915 while (next != std::string_view::npos) {
916 this->lines.emplace_back(p.substr(0, next));
917 p.remove_prefix(next + 1);
918
919 next = p.find_first_of('\n');
920 }
921 this->lines.emplace_back(p);
922
923 this->AfterLoadText();
924 this->ReflowContent();
925
926 CheckForMissingGlyphs(this);
927
928 /* The font may have changed when searching for glyphs, so ensure widget sizes are updated just in case. */
929 this->ReInit();
930}
931
932/**
933 * Search a textfile file next to the given content.

Callers 2

LoadTextfileMethod · 0.95

Calls 7

AfterLoadTextMethod · 0.95
ReflowContentMethod · 0.95
CheckForMissingGlyphsFunction · 0.85
substrMethod · 0.80
ReInitMethod · 0.80
StrMakeValidFunction · 0.70
clearMethod · 0.45

Tested by

no test coverage detected