| 154 | #endif |
| 155 | |
| 156 | Error 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 |
no test coverage detected