MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / readString

Function readString

src/OpenLoco/src/Localisation/LanguageFiles.cpp:58–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56 });
57
58 static std::unique_ptr<char[]> readString(const char* value, size_t size)
59 {
60 // Take terminating NULL character in account
61 auto str = std::make_unique<char[]>(size + 1);
62 char* out = str.get();
63
64 const utf8_t* ptr = (utf8_t*)value;
65 while (true)
66 {
67 utf32_t codepoint = readCodePoint(&ptr);
68 if (codepoint == UnicodeChar::superscript_minus || codepoint == UnicodeChar::variation_selector)
69 {
70 continue;
71 }
72
73 if (codepoint == '{')
74 {
75 std::vector<std::string_view> commands = {};
76 char* start = nullptr;
77 while (true)
78 {
79 char* pos = (char*)ptr;
80 codepoint = readCodePoint(&ptr);
81
82 if (codepoint == ' ')
83 {
84 if (start != nullptr)
85 {
86 commands.push_back(std::string_view(start, pos - start));
87 }
88 start = nullptr;
89 continue;
90 }
91
92 if (codepoint == '}')
93 {
94 if (start != nullptr)
95 {
96 commands.push_back(std::string_view(start, pos - start));
97 }
98 break;
99 }
100
101 if (start == nullptr)
102 {
103 start = pos;
104 }
105 }
106
107 auto search = kBasicCommands.find(commands[0]);
108 if (search != kBasicCommands.end())
109 {
110 *out = search->second;
111 out++;
112 }
113 else if (commands[0] == "STRINGID")
114 {
115 if (commands.size() == 1)

Callers 1

loadLanguageStringTableFunction · 0.85

Calls 9

readCodePointFunction · 0.85
errorFunction · 0.85
convertUnicodeToLocoFunction · 0.85
push_backMethod · 0.80
findMethod · 0.80
getMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected