MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / ReadFileUtf8

Function ReadFileUtf8

src/Config.cpp:152–175  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150}
151
152std::string ReadFileUtf8(const std::string& path) {
153 FILE* fp = OpenFileUtf8(path, "rb");
154 if (fp == nullptr) {
155 throw FileNotFound(path);
156 }
157
158 std::string content;
159 char buffer[4096];
160 for (;;) {
161 const size_t read = fread(buffer, 1, sizeof(buffer), fp);
162 if (read > 0) {
163 content.append(buffer, read);
164 }
165 if (read < sizeof(buffer)) {
166 if (ferror(fp)) {
167 fclose(fp);
168 throw FileNotFound(path);
169 }
170 break;
171 }
172 }
173 fclose(fp);
174 return content;
175}
176
177#if defined(_WIN32) || defined(_WIN64)
178using internal::Utf8FromWide;

Callers 1

NewFromFileMethod · 0.85

Calls 3

freadFunction · 0.85
OpenFileUtf8Function · 0.70
appendMethod · 0.45

Tested by

no test coverage detected