Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
versions.hh
Go to the documentation of this file.
1/* ========================================================================== *
2 *
3 * @file versions.hh
4 *
5 * @brief Interfaces used to perform version number analysis, especially
6 * _Semantic Version_ processing.
7 *
8 *
9 * -------------------------------------------------------------------------- */
10
11#pragma once
12
13#include <list>
14#include <nix/util.hh>
15#include <optional>
16#include <regex>
17#include <string>
18
19
20/* -------------------------------------------------------------------------- */
21
23namespace versions {
24
25/* -------------------------------------------------------------------------- */
26
30class VersionException : public std::exception
31{
32private:
33
34 std::string msg;
35
36public:
37
38 VersionException( std::string_view msg ) : msg( msg ) {}
39 const char *
40 what() const noexcept override
41 {
42 return this->msg.c_str();
43 }
44};
45
46
47/* -------------------------------------------------------------------------- */
48
50bool
51isSemver( const std::string & version );
52
54bool
55isDate( const std::string & version );
56
58bool
59isCoercibleToSemver( const std::string & version );
60
88bool
89isSemverRange( const std::string & version );
90
91
92/* -------------------------------------------------------------------------- */
93
102std::optional<std::string>
103coerceSemver( std::string_view version );
104
105
106/* -------------------------------------------------------------------------- */
107
114std::pair<int, std::string>
115runSemver( const std::list<std::string> & args );
116
125std::list<std::string>
126semverSat( const std::string & range, const std::list<std::string> & versions );
127
128
129/* -------------------------------------------------------------------------- */
130
131} // namespace versions
132
133
134/* -------------------------------------------------------------------------- *
135 *
136 *
137 *
138 * ========================================================================== */
Typed exception wrapper used for version parsing/comparison errors.
Definition: versions.hh:31
Interfaces for analyzing version numbers.
Definition: versions.cc:31
bool isSemver(const std::string &version)
Definition: versions.cc:59
std::list< std::string > semverSat(const std::string &range, const std::list< std::string > &versions)
Filter a list of versions by a node-semver semantic version range.
Definition: versions.cc:233
std::pair< int, std::string > runSemver(const std::list< std::string > &args)
Invokes node-semver by exec.
Definition: versions.cc:177
std::optional< std::string > coerceSemver(std::string_view version)
Attempt to coerce strings such as "v1.0.2" or 1.0 to valid semantic version strings.
Definition: versions.cc:92
bool isDate(const std::string &version)
Definition: versions.cc:69
bool isSemverRange(const std::string &range)
Determine if version is a valid semantic version range string.
Definition: versions.cc:153
bool isCoercibleToSemver(const std::string &version)
Definition: versions.cc:79