MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / loadFromFile

Method loadFromFile

lib/platform.cpp:173–239  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173bool Platform::loadFromFile(const std::vector<std::string>& paths, const std::string &filename, bool debug)
174{
175 if (debug)
176 std::cout << "looking for platform '" + filename + "'" << std::endl;
177
178 const bool is_abs_path = Path::isAbsolute(filename);
179 const bool is_rel_path = Path::isRelative(filename);
180
181 std::string fullfilename(filename);
182 // TODO: what if extension is not .xml?
183 // only append extension when we provide the library name is not a path - TODO: handle relative paths?
184 if (!is_abs_path && !is_rel_path && Path::getFilenameExtension(fullfilename).empty())
185 fullfilename += ".xml";
186
187 // TODO: use native separators
188 std::vector<std::string> filenames;
189 if (is_abs_path)
190 {
191 filenames.push_back(std::move(fullfilename));
192 }
193 else {
194 // TODO: drop duplicated paths
195 for (const std::string& path : paths)
196 {
197 if (path.empty())
198 continue; // TODO: error out instead?
199
200 std::string ppath = Path::fromNativeSeparators(path);
201 if (ppath.back() != '/')
202 ppath += '/';
203 // TODO: look in platforms first?
204 filenames.push_back(ppath + fullfilename);
205 filenames.push_back(ppath + "platforms/" + fullfilename);
206 }
207#ifdef FILESDIR
208 std::string filesdir = FILESDIR;
209 if (!filesdir.empty()) {
210 if (filesdir.back() != '/')
211 filesdir += '/';
212 // TODO: look in filesdir?
213 filenames.push_back(filesdir + "platforms/" + fullfilename);
214 }
215#endif
216 }
217
218 // open file..
219 tinyxml2::XMLDocument doc;
220 tinyxml2::XMLError err = tinyxml2::XML_SUCCESS;
221 for (const std::string & f : filenames) {
222 if (debug)
223 std::cout << "try to load platform file '" << f << "' ... ";
224 err = doc.LoadFile(f.c_str());
225 if (err == tinyxml2::XML_SUCCESS) {
226 if (debug)
227 std::cout << "Success" << std::endl;
228 break;
229 }
230 if (debug)

Callers 2

ProjectFileDialogMethod · 0.80
getCppcheckSettingsMethod · 0.80

Calls 4

LoadFileMethod · 0.80
ErrorStrMethod · 0.80
emptyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected