Skip to content

Commit 541fdd2

Browse files
committed
Preserve case in version number modifiers, fixes #13
1 parent fb7990a commit 541fdd2

4 files changed

Lines changed: 34 additions & 15 deletions

File tree

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release notes
22

3+
## 0.3.4 -- 2025-10-02
4+
5+
* Fixed an issue where `pkgrrxx` didn't preserve case in version numbers,
6+
leading to a failure while checking for updates when a package like
7+
`osabi-NetBSD-11.0_BETA` was installed. Reported by @drixter [#13].
8+
39
## 0.3.3 -- 2025-03-07
410

511
* Fix an issue where `pkgchkxx -ab` crashes upon trying to install the

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Process this file with autoconf to produce a configure script.
33

44
AC_PREREQ([2.71])
5-
AC_INIT([pkgchkxx], [0.3.3], [pkgsrc-users@NetBSD.org])
5+
AC_INIT([pkgchkxx], [0.3.4], [pkgsrc-users@NetBSD.org])
66
AC_CONFIG_MACRO_DIR([m4])
77
AC_CONFIG_SRCDIR([lib/pkgxx/pkgname.hxx])
88
AC_CONFIG_HEADERS([lib/pkgxx/config.h])

lib/pkgxx/pkgname.cxx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace {
99
using namespace pkgxx;
1010

1111
std::vector<pkgversion::modifier> const modifiers = {
12-
pkgversion::modifier(pkgversion::modifier::kind::ALPHA, "alpha"),
13-
pkgversion::modifier(pkgversion::modifier::kind::BETA , "beta"),
14-
pkgversion::modifier(pkgversion::modifier::kind::RC , "pre"),
15-
pkgversion::modifier(pkgversion::modifier::kind::RC , "rc"),
16-
pkgversion::modifier(pkgversion::modifier::kind::DOT , "pl"),
17-
pkgversion::modifier(pkgversion::modifier::kind::DOT , "_"),
18-
pkgversion::modifier(pkgversion::modifier::kind::DOT , ".")
12+
pkgversion::modifier(pkgversion::modifier::kind_t::ALPHA, "alpha"),
13+
pkgversion::modifier(pkgversion::modifier::kind_t::BETA , "beta"),
14+
pkgversion::modifier(pkgversion::modifier::kind_t::RC , "pre"),
15+
pkgversion::modifier(pkgversion::modifier::kind_t::RC , "rc"),
16+
pkgversion::modifier(pkgversion::modifier::kind_t::DOT , "pl"),
17+
pkgversion::modifier(pkgversion::modifier::kind_t::DOT , "_"),
18+
pkgversion::modifier(pkgversion::modifier::kind_t::DOT , ".")
1919
};
2020
}
2121

@@ -38,8 +38,15 @@ namespace pkgxx {
3838
bool found_mod = false;
3939
for (auto const& mod: modifiers) {
4040
if (ci_starts_with(it, str.end(), mod.string())) {
41-
_comps.push_back(mod);
42-
it += mod.string().size();
41+
// It's very important to construct a new modifier
42+
// object based on the original string, otherwise
43+
// its case will not be preserved (#13).
44+
auto const len = mod.string().size();
45+
_comps.emplace_back(
46+
modifier(
47+
mod.kind(),
48+
std::string(it, it + len)));
49+
it += len;
4350
found_mod = true;
4451
break;
4552
}
@@ -58,7 +65,7 @@ namespace pkgxx {
5865
break;
5966
}
6067
if (is_ascii_alpha(*it)) {
61-
_comps.emplace_back(modifier(modifier::kind::DOT, ""s));
68+
_comps.emplace_back(modifier(modifier::kind_t::DOT, ""s));
6269
_comps.emplace_back(alpha(*it++));
6370
continue;
6471
}

lib/pkgxx/pkgname.hxx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace pkgxx {
6060
/** A modifier is a specially-treated string occuring in a package version. */
6161
struct modifier {
6262
/// The kind of modifier.
63-
enum class kind: int {
63+
enum class kind_t: int {
6464
ALPHA = -3,
6565
BETA = -2,
6666
RC = -1,
@@ -69,13 +69,13 @@ namespace pkgxx {
6969

7070
/// Construct an instance of \ref modifier with its kind and
7171
/// its original string.
72-
modifier(kind k, std::string const& str) noexcept
72+
modifier(kind_t k, std::string const& str) noexcept
7373
: _kind(k)
7474
, _str(str) {}
7575

7676
/// Construct an instance of \ref modifier with its kind and
7777
/// its original string.
78-
modifier(kind k, std::string&& str) noexcept
78+
modifier(kind_t k, std::string&& str) noexcept
7979
: _kind(k)
8080
, _str(str) {}
8181

@@ -84,6 +84,12 @@ namespace pkgxx {
8484
return static_cast<int>(_kind);
8585
}
8686

87+
/// Obtain the kind of the modifier.
88+
kind_t
89+
kind() const noexcept {
90+
return _kind;
91+
}
92+
8793
/// Obtain the original string of a modifier.
8894
operator std::string const&() const noexcept {
8995
return string();
@@ -104,7 +110,7 @@ namespace pkgxx {
104110
private:
105111
friend struct std::hash<modifier>;
106112

107-
kind _kind;
113+
kind_t _kind;
108114
std::string _str;
109115
};
110116

0 commit comments

Comments
 (0)