Skip to content

Commit

Permalink
xml: use version from configuration if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Jul 2, 2023
1 parent db49687 commit 2c7f2b1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,17 @@ void ErrorMessage::deserialize(const std::string &data)
}
}

std::string ErrorMessage::getXMLHeader(const std::string& productName)
{
std::string ErrorMessage::getXMLHeader(std::string productName)
{
std::string version = CppCheck::version();
if (!productName.empty() && std::isdigit(productName.back())) {
const std::string::size_type pos = productName.find_last_not_of(".0123456789");
if (pos > 1 && pos != std::string::npos && productName[pos] == ' ') {
version = productName.substr(pos+1);
productName.erase(pos);
}
}

tinyxml2::XMLPrinter printer;

// standard xml header
Expand All @@ -393,7 +402,7 @@ std::string ErrorMessage::getXMLHeader(const std::string& productName)
printer.OpenElement("cppcheck", false);
if (!productName.empty())
printer.PushAttribute("product-name", productName.c_str());
printer.PushAttribute("version", CppCheck::version());
printer.PushAttribute("version", version.c_str());
printer.CloseElement(false);
printer.OpenElement("errors", false);

Expand Down
2 changes: 1 addition & 1 deletion lib/errorlogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class CPPCHECKLIB ErrorMessage {
*/
std::string toXML() const;

static std::string getXMLHeader(const std::string& productName);
static std::string getXMLHeader(std::string productName);
static std::string getXMLFooter();

/**
Expand Down

0 comments on commit 2c7f2b1

Please sign in to comment.