|
1 | 1 | #ifndef VERSION_WEAVER_H
|
2 | 2 | #define VERSION_WEAVER_H
|
3 | 3 | #include <optional>
|
4 |
| -#include <string_view> |
5 | 4 | #include <string>
|
| 5 | +#include <string_view> |
6 | 6 | #include <variant>
|
7 | 7 |
|
8 | 8 | namespace version_weaver {
|
9 | 9 |
|
10 |
| - // https://semver.org/#does-semver-have-a-size-limit-on-the-version-string |
11 |
| - static constexpr size_t MAX_VERSION_LENGTH = 256; |
12 |
| - |
13 |
| - bool validate(std::string_view version); |
14 |
| - bool gt(std::string_view version1, std::string_view version2); |
15 |
| - bool lt(std::string_view version1, std::string_view version2); |
16 |
| - bool satisfies(std::string_view version, std::string_view range); |
17 |
| - std::string coerce(std::string_view version); |
18 |
| - std::string minimum(std::string_view range); |
19 |
| - std::string clean(std::string_view range); |
20 |
| - |
21 |
| - // A normal version number MUST take the form X.Y.Z where X, Y, and Z are |
22 |
| - // non-negative integers, and MUST NOT contain leading zeroes. |
23 |
| - // X is the major version, Y is the minor version, and Z is the patch version. |
24 |
| - // Each element MUST increase numerically. |
25 |
| - // For instance: 1.9.0 -> 1.10.0 -> 1.11.0. |
26 |
| - struct Version { |
27 |
| - |
28 |
| - std::string_view major; |
29 |
| - std::string_view minor; |
30 |
| - std::string_view patch; |
31 |
| - |
32 |
| - // A pre-release version MAY be denoted by appending a hyphen and a series |
33 |
| - // of dot separated identifiers immediately following the patch version. |
34 |
| - // - Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]. |
35 |
| - // - Identifiers MUST NOT be empty. |
36 |
| - // - Numeric identifiers MUST NOT include leading zeroes. |
37 |
| - // |
38 |
| - // Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92, 1.0.0-x-y-z.--. |
39 |
| - std::optional<std::string_view> pre_release; |
40 |
| - |
41 |
| - // Build metadata MAY be denoted by appending a plus sign and a series of dot |
42 |
| - // separated identifiers immediately following the patch or pre-release version. |
43 |
| - // - Identifiers MUST comprise only ASCII alphanumerics and hyphens [0-9A-Za-z-]. |
44 |
| - // - Identifiers MUST NOT be empty. |
45 |
| - // Build metadata MUST be ignored when determining version precedence. |
46 |
| - // Thus two versions that differ only in the build metadata, have the same precedence. |
47 |
| - // |
48 |
| - // Examples: 1.0.0-alpha+001, 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85, 1.0.0+21AF26D3----117B344092BD. |
49 |
| - std::optional<std::string_view> build; |
50 |
| - }; |
51 |
| - |
52 |
| - enum ParseError { |
53 |
| - VERSION_LARGER_THAN_MAX_LENGTH, |
54 |
| - INVALID_INPUT, |
55 |
| - }; |
56 |
| - |
57 |
| - std::variant<Version, ParseError> parse(std::string_view version); |
58 |
| -} |
59 |
| - |
60 |
| -#endif // VERSION_WEAVER_H |
| 10 | +// https://semver.org/#does-semver-have-a-size-limit-on-the-version-string |
| 11 | +static constexpr size_t MAX_VERSION_LENGTH = 256; |
| 12 | + |
| 13 | +bool validate(std::string_view version); |
| 14 | +bool gt(std::string_view version1, std::string_view version2); |
| 15 | +bool lt(std::string_view version1, std::string_view version2); |
| 16 | +bool satisfies(std::string_view version, std::string_view range); |
| 17 | +std::string coerce(std::string_view version); |
| 18 | +std::string minimum(std::string_view range); |
| 19 | +std::string clean(std::string_view range); |
| 20 | + |
| 21 | +// A normal version number MUST take the form X.Y.Z where X, Y, and Z are |
| 22 | +// non-negative integers, and MUST NOT contain leading zeroes. |
| 23 | +// X is the major version, Y is the minor version, and Z is the patch version. |
| 24 | +// Each element MUST increase numerically. |
| 25 | +// For instance: 1.9.0 -> 1.10.0 -> 1.11.0. |
| 26 | +struct Version { |
| 27 | + std::string_view major; |
| 28 | + std::string_view minor; |
| 29 | + std::string_view patch; |
| 30 | + |
| 31 | + // A pre-release version MAY be denoted by appending a hyphen and a series |
| 32 | + // of dot separated identifiers immediately following the patch version. |
| 33 | + // - Identifiers MUST comprise only ASCII alphanumerics and hyphens |
| 34 | + // [0-9A-Za-z-]. |
| 35 | + // - Identifiers MUST NOT be empty. |
| 36 | + // - Numeric identifiers MUST NOT include leading zeroes. |
| 37 | + // |
| 38 | + // Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92, 1.0.0-x-y-z.--. |
| 39 | + std::optional<std::string_view> pre_release; |
| 40 | + |
| 41 | + // Build metadata MAY be denoted by appending a plus sign and a series of dot |
| 42 | + // separated identifiers immediately following the patch or pre-release |
| 43 | + // version. |
| 44 | + // - Identifiers MUST comprise only ASCII alphanumerics and hyphens |
| 45 | + // [0-9A-Za-z-]. |
| 46 | + // - Identifiers MUST NOT be empty. |
| 47 | + // Build metadata MUST be ignored when determining version precedence. |
| 48 | + // Thus two versions that differ only in the build metadata, have the same |
| 49 | + // precedence. |
| 50 | + // |
| 51 | + // Examples: 1.0.0-alpha+001, 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85, |
| 52 | + // 1.0.0+21AF26D3----117B344092BD. |
| 53 | + std::optional<std::string_view> build; |
| 54 | +}; |
| 55 | + |
| 56 | +enum ParseError { |
| 57 | + VERSION_LARGER_THAN_MAX_LENGTH, |
| 58 | + INVALID_INPUT, |
| 59 | +}; |
| 60 | + |
| 61 | +std::variant<Version, ParseError> parse(std::string_view version); |
| 62 | +} // namespace version_weaver |
| 63 | + |
| 64 | +#endif // VERSION_WEAVER_H |
0 commit comments