MCPcopy Create free account
hub / github.com/EasyRPG/Player / FromFile

Method FromFile

src/game_strings.cpp:193–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191}
192
193std::string Game_Strings::FromFile(std::string_view filename, int encoding, bool& do_yield) {
194 do_yield = false;
195
196 Filesystem_Stream::InputStream is = FileFinder::OpenText(filename);
197 if (!is) {
198 // Emscripten: Try to async fetch the file
199 auto* request = AsyncHandler::RequestFile("Text", filename);
200 request->SetImportantFile(true);
201 request->Start();
202 do_yield = !request->IsReady();
203
204 return {};
205 }
206
207 auto vec = Utils::ReadStream(is);
208 std::string file_content(vec.begin(), vec.end());
209
210 if (encoding == 0) {
211 lcf::Encoder enc(Player::encoding);
212 enc.Encode(file_content);
213 } else {
214 // UTF-8: Remove Byte Order Mask
215 if (file_content.size() >= 3 && file_content[0] == '\xEF' && file_content[1] == '\xBB' && file_content[2] == '\xBF') {
216 file_content.erase(0, 3);
217 }
218 }
219
220 return file_content;
221}
222
223bool Game_Strings::ToFile(Str_Params params, std::string filename, int encoding) {
224 std::string str = ToString(Get(params.string_id));

Callers

nothing calls this directly

Calls 6

SetImportantFileMethod · 0.80
IsReadyMethod · 0.80
StartMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected