| 960 | } |
| 961 | |
| 962 | std::string getClassification(const std::string &guideline, ReportType reportType) { |
| 963 | if (guideline.empty()) |
| 964 | return ""; |
| 965 | |
| 966 | const auto getClassification = [](const std::vector<checkers::Info> &info, const std::string &guideline) -> std::string { |
| 967 | const auto it = std::find_if(info.cbegin(), info.cend(), [&](const checkers::Info &i) { |
| 968 | return caseInsensitiveStringCompare(i.guideline, guideline) == 0; |
| 969 | }); |
| 970 | if (it == info.cend()) |
| 971 | return ""; |
| 972 | return it->classification; |
| 973 | }; |
| 974 | |
| 975 | switch (reportType) { |
| 976 | case ReportType::autosar: |
| 977 | return getClassification(checkers::autosarInfo, guideline); |
| 978 | case ReportType::certC: |
| 979 | return getClassification(checkers::certCInfo, guideline); |
| 980 | case ReportType::certCpp: |
| 981 | return getClassification(checkers::certCppInfo, guideline); |
| 982 | case ReportType::misraC2012: |
| 983 | case ReportType::misraC2023: |
| 984 | case ReportType::misraC2025: |
| 985 | { |
| 986 | const bool isDirective = guideline.rfind("Dir ", 0) == 0; |
| 987 | |
| 988 | const std::size_t offset = isDirective ? 4 : 0; |
| 989 | auto components = splitString(guideline.substr(offset), '.'); |
| 990 | if (components.size() != 2) |
| 991 | return ""; |
| 992 | |
| 993 | const int a = std::stoi(components[0]); |
| 994 | const int b = std::stoi(components[1]); |
| 995 | |
| 996 | const std::vector<checkers::MisraInfo> *info = nullptr; |
| 997 | switch (reportType) { |
| 998 | case ReportType::misraC2012: |
| 999 | info = isDirective ? &checkers::misraC2012Directives : &checkers::misraC2012Rules; |
| 1000 | break; |
| 1001 | case ReportType::misraC2023: |
| 1002 | info = isDirective ? &checkers::misraC2023Directives : &checkers::misraC2023Rules; |
| 1003 | break; |
| 1004 | case ReportType::misraC2025: |
| 1005 | info = isDirective ? &checkers::misraC2025Directives : &checkers::misraC2025Rules; |
| 1006 | break; |
| 1007 | default: |
| 1008 | cppcheck::unreachable(); |
| 1009 | } |
| 1010 | |
| 1011 | const auto it = std::find_if(info->cbegin(), info->cend(), [&](const checkers::MisraInfo &i) { |
| 1012 | return i.a == a && i.b == b; |
| 1013 | }); |
| 1014 | |
| 1015 | return it == info->cend() ? "" : it->str; |
| 1016 | } |
| 1017 | case ReportType::misraCpp2008: |
| 1018 | case ReportType::misraCpp2023: |
| 1019 | { |