From 78e1c398187c2dbed2bb8ea4aa45589a5b749aa3 Mon Sep 17 00:00:00 2001 From: Oded Katz <88981719+katzoded@users.noreply.github.com> Date: Thu, 13 Apr 2023 09:18:59 -0700 Subject: [PATCH] refactor request coming from original repo PR (#2) --- include/semver/semver.hpp | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/include/semver/semver.hpp b/include/semver/semver.hpp index 0e82563..5200476 100644 --- a/include/semver/semver.hpp +++ b/include/semver/semver.hpp @@ -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 = '.'; @@ -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(std::stoull(version_part)); + return static_cast(std::stoull(version_part)); } inline std::vector split(const std::string& text, const char& delimiter) { @@ -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()) { @@ -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)) { @@ -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; @@ -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; @@ -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}, @@ -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; } @@ -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 = ""; @@ -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); }