Skip to content

Commit 72245b1

Browse files
authored
xml: use version from configuration if provided (#5215)
1 parent db49687 commit 72245b1

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/errorlogger.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,17 @@ void ErrorMessage::deserialize(const std::string &data)
379379
}
380380
}
381381

382-
std::string ErrorMessage::getXMLHeader(const std::string& productName)
383-
{
382+
std::string ErrorMessage::getXMLHeader(std::string productName)
383+
{
384+
std::string version = CppCheck::version();
385+
if (!productName.empty() && std::isdigit(productName.back())) {
386+
const std::string::size_type pos = productName.find_last_not_of(".0123456789");
387+
if (pos > 1 && pos != std::string::npos && productName[pos] == ' ') {
388+
version = productName.substr(pos+1);
389+
productName.erase(pos);
390+
}
391+
}
392+
384393
tinyxml2::XMLPrinter printer;
385394

386395
// standard xml header
@@ -393,7 +402,7 @@ std::string ErrorMessage::getXMLHeader(const std::string& productName)
393402
printer.OpenElement("cppcheck", false);
394403
if (!productName.empty())
395404
printer.PushAttribute("product-name", productName.c_str());
396-
printer.PushAttribute("version", CppCheck::version());
405+
printer.PushAttribute("version", version.c_str());
397406
printer.CloseElement(false);
398407
printer.OpenElement("errors", false);
399408

lib/errorlogger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class CPPCHECKLIB ErrorMessage {
148148
*/
149149
std::string toXML() const;
150150

151-
static std::string getXMLHeader(const std::string& productName);
151+
static std::string getXMLHeader(std::string productName);
152152
static std::string getXMLFooter();
153153

154154
/**

0 commit comments

Comments
 (0)