Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Patches for clean Fedora RPM builds that pass unit tests #123

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
72 changes: 40 additions & 32 deletions libsrc/core/version.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#ifndef NETGEN_CORE_VERSION_HPP
#define NETGEN_CORE_VERSION_HPP

#include <ostream>
#include <iostream>
#include <string>
#include <tuple>
#include "exception.hpp"

#include "ngcore_api.hpp"

Expand All @@ -18,37 +19,44 @@ namespace ngcore
VersionInfo() = default;
VersionInfo(std::string vstring)
{
minor_ = release = patch = 0;
git_hash = "";
if(vstring.substr(0,1) == "v")
vstring = vstring.substr(1,vstring.size()-1);
auto dot = vstring.find('.');
mayor_ = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('.');
minor_ = std::stoi(vstring.substr(0,dot));
if (dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('-');
release = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1,vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('-');
patch = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
git_hash = vstring;
}
}
}
std::string save = vstring;
try {
minor_ = release = patch = 0;
git_hash = "";
if(vstring.substr(0,1) == "v")
vstring = vstring.substr(1,vstring.size()-1);
auto dot = vstring.find('.');
mayor_ = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compare with std::string::npos, instead of type-casting.

else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

substr() returns up to the end when the second argument is omitted (i.e. uses the std::string::npos default argument).

if(!vstring.empty())
{
dot = vstring.find('.');
minor_ = std::stoi(vstring.substr(0,dot));
if (dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('-');
release = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1,vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('-');
patch = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
git_hash = vstring;
}
}
}
} catch(...) {
std::cerr << "Malformed NETGEN_VERSION (" << save <<"\n";
std::cerr << "Micompiled/mispackaged Netgen library\n";
abort();
}
}
VersionInfo(const char* cstr) : VersionInfo(std::string(cstr)) { }

Expand Down