Skip to content

Commit

Permalink
refactor request coming from original repo PR (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
katzoded authored Apr 13, 2023
1 parent f614975 commit 78e1c39
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions include/semver/semver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SOFTWARE.
namespace semver
{

using build_identifier_part = uint64_t;
using numeric_part = uint64_t;

const std::string default_prerelease_part = "0";
const char prerelease_delimiter = '.';
Expand All @@ -49,9 +49,9 @@ namespace semver
semver_exception(const std::string& message) : std::runtime_error(message) { }
};

inline build_identifier_part parse_build_identifier_part(const std::string& version_part)
inline numeric_part parse_numeric_part(const std::string& version_part)
{
return static_cast<build_identifier_part>(std::stoull(version_part));
return static_cast<numeric_part>(std::stoull(version_part));
}

inline std::vector<std::string> split(const std::string& text, const char& delimiter) {
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace semver
private:
bool m_numeric = false;
std::string m_value;
build_identifier_part m_numeric_value;
numeric_part m_numeric_value;
public:
prerelease_part(const std::string& part) {
if (part.empty()) {
Expand All @@ -93,7 +93,7 @@ namespace semver
throw semver_exception(
"Pre-release part '" + part + "' is numeric but contains a leading zero.");
}
m_numeric_value = parse_build_identifier_part(part);
m_numeric_value = parse_numeric_part(part);
m_numeric = true;
}
if (!is_valid_prerelease(part)) {
Expand All @@ -105,7 +105,7 @@ namespace semver

bool numeric() const { return m_numeric; }
std::string value() const { return m_value; }
build_identifier_part numeric_value() const { return m_numeric_value; }
numeric_part numeric_value() const { return m_numeric_value; }

int compare(const prerelease_part& other) const {
if (m_numeric && !other.m_numeric) return -1;
Expand Down Expand Up @@ -205,9 +205,9 @@ namespace semver

class version {
private:
build_identifier_part m_major;
build_identifier_part m_minor;
build_identifier_part m_patch;
numeric_part m_major;
numeric_part m_minor;
numeric_part m_patch;
prerelease_descriptor m_prerelease;
std::string m_build_meta;

Expand All @@ -224,9 +224,9 @@ namespace semver
return 0;
}
public:
version(build_identifier_part major = 0,
build_identifier_part minor = 0,
build_identifier_part patch = 0,
version(numeric_part major = 0,
numeric_part minor = 0,
numeric_part patch = 0,
std::string prerelease = "",
std::string build_meta = "")
: m_major{major},
Expand All @@ -235,9 +235,9 @@ namespace semver
m_prerelease{prerelease_descriptor::parse(prerelease)},
m_build_meta{build_meta} { }

build_identifier_part major() const { return m_major; }
build_identifier_part minor() const { return m_minor; }
build_identifier_part patch() const { return m_patch; }
numeric_part major() const { return m_major; }
numeric_part minor() const { return m_minor; }
numeric_part patch() const { return m_patch; }
std::string prerelease() const { return m_prerelease.str(); }
std::string build_meta() const { return m_build_meta; }

Expand Down Expand Up @@ -314,9 +314,9 @@ namespace semver
static version parse(const std::string& version_str, bool strict = true) {
std::regex regex(strict ? version_pattern : loose_version_pattern);
std::cmatch match;
build_identifier_part major;
build_identifier_part minor;
build_identifier_part patch;
numeric_part major;
numeric_part minor;
numeric_part patch;
std::string prerelease = "";
std::string build_meta = "";

Expand All @@ -335,13 +335,13 @@ namespace semver

try {
if (strict && major_m.matched && minor_m.matched && patch_m.matched) {
major = parse_build_identifier_part(major_m);
minor = parse_build_identifier_part(minor_m);
patch = parse_build_identifier_part(patch_m);
major = parse_numeric_part(major_m);
minor = parse_numeric_part(minor_m);
patch = parse_numeric_part(patch_m);
} else if (!strict && major_m.matched) {
major = parse_build_identifier_part(major_m);
minor = minor_m.matched ? parse_build_identifier_part(minor_m) : 0;
patch = patch_m.matched ? parse_build_identifier_part(patch_m) : 0;
major = parse_numeric_part(major_m);
minor = minor_m.matched ? parse_numeric_part(minor_m) : 0;
patch = patch_m.matched ? parse_numeric_part(patch_m) : 0;
} else {
throw semver_exception("Invalid version: " + version_str);
}
Expand Down

0 comments on commit 78e1c39

Please sign in to comment.