| 110 | |
| 111 | |
| 112 | std::string SuppressionList::parseXmlFile(const char *filename) |
| 113 | { |
| 114 | tinyxml2::XMLDocument doc; |
| 115 | const tinyxml2::XMLError error = doc.LoadFile(filename); |
| 116 | if (error != tinyxml2::XML_SUCCESS) |
| 117 | return std::string("failed to load suppressions XML '") + filename + "' (" + tinyxml2::XMLDocument::ErrorIDToName(error) + ")."; |
| 118 | |
| 119 | const tinyxml2::XMLElement * const rootnode = doc.FirstChildElement(); |
| 120 | if (!rootnode) |
| 121 | return std::string("failed to load suppressions XML '") + filename + "' (no root node found)."; |
| 122 | // TODO: check for proper root node 'suppressions' |
| 123 | for (const tinyxml2::XMLElement * e = rootnode->FirstChildElement(); e; e = e->NextSiblingElement()) { |
| 124 | if (std::strcmp(e->Name(), "suppress") != 0) |
| 125 | return std::string("invalid suppression xml file '") + filename + "', expected 'suppress' element but got a '" + e->Name() + "'."; |
| 126 | |
| 127 | Suppression s; |
| 128 | for (const tinyxml2::XMLElement * e2 = e->FirstChildElement(); e2; e2 = e2->NextSiblingElement()) { |
| 129 | const char *name = e2->Name(); |
| 130 | const char *text = empty_if_null(e2->GetText()); |
| 131 | if (std::strcmp(name, "id") == 0) |
| 132 | s.errorId = text; |
| 133 | else if (std::strcmp(name, "fileName") == 0) |
| 134 | s.fileName = Path::simplifyPath(text); |
| 135 | else if (std::strcmp(name, "lineNumber") == 0) |
| 136 | s.lineNumber = strToInt<int>(text); |
| 137 | else if (std::strcmp(name, "symbolName") == 0) |
| 138 | s.symbolName = text; |
| 139 | else if (*text && std::strcmp(name, "hash") == 0) |
| 140 | s.hash = strToInt<std::size_t>(text); |
| 141 | else |
| 142 | return std::string("unknown element '") + name + "' in suppressions XML '" + filename + "', expected id/fileName/lineNumber/symbolName/hash."; |
| 143 | } |
| 144 | |
| 145 | std::string err = addSuppression(std::move(s)); |
| 146 | if (!err.empty()) |
| 147 | return err; |
| 148 | } |
| 149 | |
| 150 | return ""; |
| 151 | } |
| 152 | |
| 153 | std::vector<SuppressionList::Suppression> SuppressionList::parseMultiSuppressComment(const std::string &comment, std::string *errorMessage) |
| 154 | { |