MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / read_all_file_utf8

Function read_all_file_utf8

modules/mono/utils/string_utils.cpp:156–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154#endif
155
156Error read_all_file_utf8(const String &p_path, String &r_content) {
157 Vector<uint8_t> sourcef;
158 Error err;
159 Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
160 ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot open file '" + p_path + "'.");
161
162 uint64_t len = f->get_length();
163 sourcef.resize(len + 1);
164 uint8_t *w = sourcef.ptrw();
165 uint64_t r = f->get_buffer(w, len);
166 ERR_FAIL_COND_V(r != len, ERR_CANT_OPEN);
167 w[len] = 0;
168
169 String source;
170 if (source.append_utf8((const char *)w, len) != OK) {
171 ERR_FAIL_V(ERR_INVALID_DATA);
172 }
173
174 r_content = source;
175 return OK;
176}
177
178/// @todo Move to variadic templates once we upgrade to C++11
179

Callers 1

load_source_codeMethod · 0.85

Calls 5

get_lengthMethod · 0.45
resizeMethod · 0.45
ptrwMethod · 0.45
get_bufferMethod · 0.45
append_utf8Method · 0.45

Tested by

no test coverage detected