MCPcopy Create free account
hub / github.com/Kitware/CMake / ReadJsonFile

Method ReadJsonFile

Source/cmFileAPI.cxx:173–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173bool cmFileAPI::ReadJsonFile(std::string const& file, Json::Value& value,
174 std::string& error)
175{
176 std::vector<char> content;
177
178 cmsys::ifstream fin;
179 if (!cmSystemTools::FileIsDirectory(file)) {
180 fin.open(file.c_str(), std::ios::binary);
181 }
182 auto finEnd = fin.rdbuf()->pubseekoff(0, std::ios::end);
183 if (finEnd > 0) {
184 size_t finSize = finEnd;
185 try {
186 // Allocate a buffer to read the whole file.
187 content.resize(finSize);
188
189 // Now read the file from the beginning.
190 fin.seekg(0, std::ios::beg);
191 fin.read(content.data(), finSize);
192 } catch (...) {
193 fin.setstate(std::ios::failbit);
194 }
195 }
196 fin.close();
197 if (!fin) {
198 value = Json::Value();
199 error = "failed to read from file";
200 return false;
201 }
202
203 // Parse our buffer as json.
204 if (!this->JsonReader->parse(content.data(), content.data() + content.size(),
205 &value, &error)) {
206 value = Json::Value();
207 return false;
208 }
209
210 return true;
211}
212
213std::string cmFileAPI::WriteJsonFile(
214 Json::Value const& value, std::string const& prefix,

Callers 1

ReadClientQueryMethod · 0.95

Calls 9

c_strMethod · 0.80
ValueClass · 0.70
openMethod · 0.45
resizeMethod · 0.45
readMethod · 0.45
dataMethod · 0.45
closeMethod · 0.45
parseMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected