| 208 | } |
| 209 | |
| 210 | SuppressionList::Suppression SuppressionList::parseLine(std::string line) |
| 211 | { |
| 212 | SuppressionList::Suppression suppression; |
| 213 | |
| 214 | // Strip any end of line comments |
| 215 | std::string::size_type endpos = std::min(line.find('#'), line.find("//")); |
| 216 | if (endpos != std::string::npos) { |
| 217 | while (endpos > 0 && std::isspace(line[endpos-1])) { |
| 218 | endpos--; |
| 219 | } |
| 220 | line.resize(endpos); |
| 221 | } |
| 222 | |
| 223 | const auto parts = splitString(line, '\n'); |
| 224 | const std::string& suppr_l = parts[0]; |
| 225 | |
| 226 | const std::string::size_type first_sep = suppr_l.find(':'); |
| 227 | suppression.errorId = suppr_l.substr(0, first_sep); |
| 228 | if (first_sep != std::string::npos) { |
| 229 | suppression.fileName = suppr_l.substr(first_sep+1); |
| 230 | if (!suppression.fileName.empty()) { |
| 231 | // TODO: this only works with files which have an extension |
| 232 | // If there is not a dot after the last colon in "file" then |
| 233 | // the colon is a separator and the contents after the colon |
| 234 | // is a line number.. |
| 235 | |
| 236 | // Get position of last colon |
| 237 | const std::string::size_type pos = suppression.fileName.rfind(':'); |
| 238 | |
| 239 | // if a colon is found and there is no dot after it.. |
| 240 | if (pos != std::string::npos && |
| 241 | suppression.fileName.find('.', pos) == std::string::npos) |
| 242 | { |
| 243 | // parse out the line number |
| 244 | const std::string line_s = suppression.fileName.substr(pos+1); |
| 245 | suppression.fileName.erase(pos); |
| 246 | |
| 247 | if (suppression.fileName.empty()) |
| 248 | throw std::runtime_error("filename is missing"); |
| 249 | |
| 250 | try { |
| 251 | suppression.lineNumber = strToInt<int>(line_s); |
| 252 | } catch (const std::runtime_error& e) { |
| 253 | throw std::runtime_error(std::string("invalid line number (") + e.what() + ")"); |
| 254 | } |
| 255 | } |
| 256 | suppression.fileName = Path::simplifyPath(suppression.fileName); |
| 257 | } else { |
| 258 | throw std::runtime_error("filename is missing"); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | // TODO: make this optional - do we even encounter this in production code? |
| 263 | // when parsing string generated internally by toString() there can be newline |
| 264 | for (std::size_t i = 1; i < parts.size(); ++i) { |
| 265 | if (startsWith(parts[i], "symbol=")) |
| 266 | suppression.symbolName = parts[i].substr(7); |
| 267 | else if (parts[i] == "polyspace=1") |
nothing calls this directly
no test coverage detected