|
22 | 22 | #include "vfvalue.h" |
23 | 23 |
|
24 | 24 | #include <fstream> |
| 25 | +#include <sstream> |
25 | 26 |
|
26 | 27 | #include "json.h" |
27 | 28 |
|
@@ -545,3 +546,46 @@ bool Settings::isPremiumEnabled(const char id[]) const |
545 | 546 | return true; |
546 | 547 | return false; |
547 | 548 | } |
| 549 | + |
| 550 | +void Settings::setMisraRuleTexts(const ExecuteCmdFn& executeCommand) |
| 551 | +{ |
| 552 | + if (premiumArgs.find("--misra-c-20") != std::string::npos) { |
| 553 | + const auto it = std::find_if(addonInfos.cbegin(), addonInfos.cend(), [](const AddonInfo& a) { |
| 554 | + return a.name == "premiumaddon.json"; |
| 555 | + }); |
| 556 | + if (it != addonInfos.cend()) { |
| 557 | + std::string arg; |
| 558 | + if (premiumArgs.find("--misra-c-2023") != std::string::npos) |
| 559 | + arg = "--misra-c-2023-rule-texts"; |
| 560 | + else |
| 561 | + arg = "--misra-c-2012-rule-texts"; |
| 562 | + std::string output; |
| 563 | + executeCommand(it->executable, {arg}, "2>&1", output); |
| 564 | + setMisraRuleTexts(output); |
| 565 | + } |
| 566 | + } |
| 567 | +} |
| 568 | + |
| 569 | +void Settings::setMisraRuleTexts(const std::string& data) |
| 570 | +{ |
| 571 | + mMisraRuleTexts.clear(); |
| 572 | + std::istringstream istr(data); |
| 573 | + std::string line; |
| 574 | + while (std::getline(istr, line)) { |
| 575 | + std::string::size_type pos = line.find(' '); |
| 576 | + if (pos == std::string::npos) |
| 577 | + continue; |
| 578 | + std::string id = line.substr(0, pos); |
| 579 | + std::string text = line.substr(pos + 1); |
| 580 | + if (id.empty() || text.empty()) |
| 581 | + continue; |
| 582 | + mMisraRuleTexts[id] = text; |
| 583 | + } |
| 584 | +} |
| 585 | + |
| 586 | +std::string Settings::getMisraRuleText(const std::string& id, const std::string& text) const { |
| 587 | + if (id.compare(0, 9, "misra-c20") != 0) |
| 588 | + return text; |
| 589 | + const auto it = mMisraRuleTexts.find(id.substr(id.rfind('-') + 1)); |
| 590 | + return it != mMisraRuleTexts.end() ? it->second : text; |
| 591 | +} |
0 commit comments