1#ifndef SOURCEMETA_CORE_SEMVER_H_
2#define SOURCEMETA_CORE_SEMVER_H_
4#ifndef SOURCEMETA_CORE_SEMVER_EXPORT
5#include <sourcemeta/core/semver_export.h>
9#include <sourcemeta/core/semver_error.h>
12#include <sourcemeta/core/preprocessor.h>
28namespace sourcemeta::core {
33class SOURCEMETA_CORE_SEMVER_EXPORT
SemVer {
36 enum class Mode : std::uint8_t {
53 [[nodiscard]]
static auto from(std::string_view input,
55 -> std::optional<SemVer>;
58 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto major() const noexcept
64 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto minor() const noexcept
70 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto patch() const noexcept
76 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto pre_release() const noexcept
78 return this->pre_release_;
82 [[nodiscard]] SOURCEMETA_FORCEINLINE
inline auto build() const noexcept
92 SOURCEMETA_FORCEINLINE
inline auto
93 operator==(
const SemVer &other)
const noexcept ->
bool {
94 return this->major_ == other.major_ && this->minor_ == other.minor_ &&
95 this->patch_ == other.patch_ &&
96 this->pre_release_ == other.pre_release_ &&
97 this->build_ == other.build_;
100 auto operator<(
const SemVer &other)
const noexcept -> bool;
102 SOURCEMETA_FORCEINLINE
inline auto
103 operator!=(
const SemVer &other)
const noexcept ->
bool {
104 return !(*
this == other);
107 SOURCEMETA_FORCEINLINE
inline auto
108 operator>(
const SemVer &other)
const noexcept ->
bool {
109 return other < *
this;
112 SOURCEMETA_FORCEINLINE
inline auto
113 operator<=(
const SemVer &other)
const noexcept ->
bool {
114 return !(other < *
this);
117 SOURCEMETA_FORCEINLINE
inline auto
118 operator>=(
const SemVer &other)
const noexcept ->
bool {
119 return !(*
this < other);
127 std::uint64_t major_{0};
128 std::uint64_t minor_{0};
129 std::uint64_t patch_{0};
131#pragma warning(disable : 4251)
133 std::string_view pre_release_;
134 std::string_view build_;
136#pragma warning(default : 4251)
@ Strict
The cookie is withheld from every cross-site request.
Definition http.h:269
SOURCEMETA_FORCEINLINE auto minor() const noexcept -> std::uint64_t
The minor version number.
Definition semver.h:64
SOURCEMETA_FORCEINLINE auto pre_release() const noexcept -> std::string_view
The pre-release identifier, or empty if none is present.
Definition semver.h:76
SOURCEMETA_FORCEINLINE auto major() const noexcept -> std::uint64_t
The major version number.
Definition semver.h:58
auto to_string() const -> std::string
Serialise the version back into its string representation.
SOURCEMETA_FORCEINLINE auto build() const noexcept -> std::string_view
The build metadata, or empty if none is present.
Definition semver.h:82
Mode
The level of strictness applied when parsing a version string.
Definition semver.h:36
@ Strict
Require a fully compliant version string.
Definition semver.h:38
SOURCEMETA_FORCEINLINE auto patch() const noexcept -> std::uint64_t
The patch version number.
Definition semver.h:70
SemVer(std::string_view input, Mode mode=Mode::Strict)
Construct a version by parsing the given string, throwing on failure.
static auto from(std::string_view input, Mode mode=Mode::Strict) noexcept -> std::optional< SemVer >
Parse a version from the given string, returning no value on failure.