Skip to content

Commit 1f88418

Browse files
authored
Merge pull request #102 from Geod24/mlang_fix_3.0.10
Version handling: Handle multiple digits
2 parents cb15445 + 4ee0e55 commit 1f88418

File tree

1 file changed

+47
-20
lines changed

1 file changed

+47
-20
lines changed

source/deimos/openssl/opensslv.di

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,73 +19,100 @@ version (DeimosOpenSSL_1_0_0)
1919
{
2020
// https://www.openssl.org/news/changelog.html#openssl-100
2121
// OpenSSL 1.0.0t was released 2015-12-03
22-
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.0t";
22+
public enum OpenSSLVersion = parseOpenSSLVersion("1.0.0t");
2323
}
2424
else version (DeimosOpenSSL_1_0_1)
2525
{
2626
// https://www.openssl.org/news/changelog.html#openssl-101
2727
// OpenSSL 1.0.1u was released 2016-09-22
28-
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.1u";
28+
public enum OpenSSLVersion = parseOpenSSLVersion("1.0.1u");
2929
}
3030
else version (DeimosOpenSSL_1_0_2)
3131
{
3232
// https://www.openssl.org/news/changelog.html#openssl-102
3333
// OpenSSL 1.0.2t was released 2019-09-10
34-
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.0.2t";
34+
public enum OpenSSLVersion = parseOpenSSLVersion("1.0.2t");
3535
}
3636
else version (DeimosOpenSSL_1_1_0)
3737
{
3838
// https://www.openssl.org/news/changelog.html#openssl-110
3939
// OpenSSL 1.1.0l was released 2019-09-10
40-
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.0l";
40+
public enum OpenSSLVersion = parseOpenSSLVersion("1.1.0l");
4141
}
4242
else version (DeimosOpenSSL_1_1_1)
4343
{
4444
// https://www.openssl.org/news/changelog.html#openssl-111
4545
// OpenSSL 1.1.1m was released 2021-12-14
46-
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.1m";
46+
public enum OpenSSLVersion = parseOpenSSLVersion("1.1.1m");
4747
}
4848
else version (DeimosOpenSSL_3_0)
4949
{
5050
// https://www.openssl.org/news/changelog.html#openssl-30
5151
// OpenSSL 3.0.3 was released 2022-05-03
52-
public alias OpenSSLVersion = OpenSSLVersionTemplate!"3.0.3";
52+
public enum OpenSSLVersion = parseOpenSSLVersion("3.0.3");
5353
}
5454
else version (DeimosOpenSSLAutoDetect)
5555
{
5656
import deimos.openssl.version_;
5757

58-
public alias OpenSSLVersion = OpenSSLVersionTemplate!OpenSSLTextVersion;
58+
public enum OpenSSLVersion = parseOpenSSLVersion(OpenSSLTextVersion);
5959
}
6060
else
6161
{
6262
// It was decided in https://github.com/D-Programming-Deimos/openssl/pull/66
6363
// that we should fall back to the latest supported version of the bindings,
6464
// should the user provide neither explicit version nor `DeimosOpenSSLAutoDetect`
65-
public alias OpenSSLVersion = OpenSSLVersionTemplate!"1.1.0h";
65+
public enum OpenSSLVersion = parseOpenSSLVersion("1.1.0h");
6666
}
6767

6868
// Publicly aliased above
69-
private struct OpenSSLVersionTemplate (string textVersion)
69+
private struct OpenSSLVersionStruct
7070
{
71-
enum text = textVersion;
71+
string text;
72+
uint major, minor, patch;
73+
int build;
74+
}
75+
76+
private OpenSSLVersionStruct parseOpenSSLVersion()(string textVersion)
77+
{
78+
OpenSSLVersionStruct v;
79+
80+
import std.ascii : isDigit;
81+
import std.algorithm.iteration : splitter;
82+
import std.algorithm.searching : canFind;
83+
import std.conv : to;
84+
import std.range : dropExactly;
7285

73-
enum int major = (text[0] - '0');
74-
static assert (major >= 0);
86+
v.text = textVersion;
7587

76-
enum int minor = (text[2] - '0');
77-
static assert (minor >= 0);
88+
v.major = textVersion.splitter('.')
89+
.front.to!uint;
90+
assert (v.major >= 0);
7891

79-
enum int patch = (text[4] - '0');
80-
static assert (patch >= 0);
92+
v.minor = textVersion.splitter('.')
93+
.dropExactly(1)
94+
.front.to!uint;
95+
assert (v.minor >= 0);
8196

82-
static if (text.length == "1.1.0h".length)
97+
// `std.algorithm.iteration : splitWhen` not usable at CT
98+
// so we're using `canFind`.
99+
string patchText = textVersion.splitter('.')
100+
.dropExactly(2).front;
101+
auto patchChar = patchText.canFind!(
102+
(dchar c) => !c.isDigit());
103+
104+
v.patch = patchText[0 .. $ - patchChar].to!uint;
105+
assert (v.patch >= 0);
106+
107+
if (patchChar)
83108
{
84-
enum int build = (text[5] - '`');
85-
static assert (build >= 0);
109+
v.build = (patchText[$ - 1] - '`');
110+
assert (v.build >= 0);
86111
}
87112
else
88-
enum int build = 0;
113+
v.build = 0;
114+
115+
return v;
89116
}
90117

91118
/* Numeric release version identifier:

0 commit comments

Comments
 (0)