| 1055 | } |
| 1056 | |
| 1057 | std::string getGuideline(const std::string &errId, ReportType reportType, |
| 1058 | const std::map<std::string, std::string> &guidelineMapping, |
| 1059 | Severity severity) |
| 1060 | { |
| 1061 | std::string guideline; |
| 1062 | |
| 1063 | switch (reportType) { |
| 1064 | case ReportType::autosar: |
| 1065 | if (errId.rfind("premium-autosar-", 0) == 0) { |
| 1066 | guideline = errId.substr(16); |
| 1067 | break; |
| 1068 | } |
| 1069 | if (errId.rfind("premium-misra-cpp-2008-", 0) == 0) |
| 1070 | guideline = "M" + errId.substr(23); |
| 1071 | break; |
| 1072 | case ReportType::certC: |
| 1073 | case ReportType::certCpp: |
| 1074 | if (errId.rfind("premium-cert-", 0) == 0) { |
| 1075 | guideline = errId.substr(13); |
| 1076 | std::transform(guideline.begin(), guideline.end(), |
| 1077 | guideline.begin(), static_cast<int (*)(int)>(std::toupper)); |
| 1078 | } |
| 1079 | break; |
| 1080 | case ReportType::misraC2012: |
| 1081 | case ReportType::misraC2023: |
| 1082 | case ReportType::misraC2025: |
| 1083 | if (errId.rfind("misra-c20", 0) == 0 || errId.rfind("premium-misra-c-20", 0) == 0) { |
| 1084 | auto pos1 = errId.find("20") + 5; |
| 1085 | if (pos1 >= errId.size()) |
| 1086 | break; |
| 1087 | if (errId.compare(pos1,4,"dir-",0,4) == 0) |
| 1088 | pos1 += 4; |
| 1089 | const auto endpos = errId.find('-', pos1); |
| 1090 | guideline = errId.substr(pos1, endpos-pos1); |
| 1091 | } |
| 1092 | break; |
| 1093 | case ReportType::misraCpp2008: |
| 1094 | if (errId.rfind("premium-misra-cpp-2008", 0) == 0) |
| 1095 | guideline = errId.substr(23); |
| 1096 | break; |
| 1097 | case ReportType::misraCpp2023: |
| 1098 | if (errId.rfind("premium-misra-cpp-2023", 0) == 0) |
| 1099 | guideline = errId.substr(errId.rfind('-') + 1); |
| 1100 | break; |
| 1101 | default: |
| 1102 | break; |
| 1103 | } |
| 1104 | |
| 1105 | if (!guideline.empty()) { |
| 1106 | if (errId.find("-dir-") != std::string::npos) |
| 1107 | guideline = "Dir " + guideline; |
| 1108 | return guideline; |
| 1109 | } |
| 1110 | |
| 1111 | auto it = guidelineMapping.find(errId); |
| 1112 | |
| 1113 | if (it != guidelineMapping.cend()) |
| 1114 | return it->second; |