Skip to content

Commit 9f04fe5

Browse files
authored
Merge pull request #108 from CyberShadow/107-openssl-+-stdconv-=-linker-error
deimos.openssl.opensslv: Remove use of Phobos
2 parents da92bb3 + aff12f3 commit 9f04fe5

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

source/deimos/openssl/opensslv.di

+43-23
Original file line numberDiff line numberDiff line change
@@ -75,45 +75,65 @@ private struct OpenSSLVersionStruct
7575

7676
private OpenSSLVersionStruct parseOpenSSLVersion()(string textVersion)
7777
{
78-
OpenSSLVersionStruct v;
78+
// Note: we avoid using Phobos here to avoid DMD bugs,
79+
// e.g. https://issues.dlang.org/show_bug.cgi?id=24146
80+
81+
bool isDigit(char c) { return c >= '0' && c <= '9'; }
82+
83+
string[] split(string s, char delim)
84+
{
85+
string[] result;
86+
size_t start;
87+
for (size_t i = 0; i < s.length; i++)
88+
if (s[i] == delim)
89+
{
90+
result ~= s[start .. i];
91+
start = i + 1;
92+
}
93+
if (start != s.length)
94+
result ~= s[start .. s.length];
95+
return result;
96+
}
97+
98+
uint parseUnsignedDecimal(string s)
99+
{
100+
assert(s.length);
101+
uint result;
102+
foreach (c; s)
103+
{
104+
assert(isDigit(c));
105+
result = result * 10 + (c - '0');
106+
}
107+
return result;
108+
}
79109

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;
110+
OpenSSLVersionStruct v;
85111

86112
v.text = textVersion;
87113

88-
textVersion = textVersion.splitter('-').front;
114+
textVersion = split(textVersion, '-')[0];
115+
auto parts = split(textVersion, '.');
89116

90-
v.major = textVersion.splitter('.')
91-
.front.to!uint;
117+
v.major = parseUnsignedDecimal(parts[0]);
92118
assert (v.major >= 0);
93119

94-
v.minor = textVersion.splitter('.')
95-
.dropExactly(1)
96-
.front.to!uint;
120+
v.minor = parseUnsignedDecimal(parts[1]);
97121
assert (v.minor >= 0);
98122

99123
// `std.algorithm.iteration : splitWhen` not usable at CT
100124
// so we're using `canFind`.
101-
string patchText = textVersion.splitter('.')
102-
.dropExactly(2).front;
103-
auto patchChar = patchText.canFind!(
104-
(dchar c) => !c.isDigit());
105-
106-
v.patch = patchText[0 .. $ - patchChar].to!uint;
107-
assert (v.patch >= 0);
108-
109-
if (patchChar)
125+
string patchText = parts[2];
126+
if (!isDigit(patchText[$ - 1]))
110127
{
111-
v.build = (patchText[$ - 1] - '`');
112-
assert (v.build >= 0);
128+
v.build = patchText[$ - 1] - '`';
129+
patchText = patchText[0 .. $ - 1];
113130
}
114131
else
115132
v.build = 0;
116133

134+
v.patch = parseUnsignedDecimal(patchText);
135+
assert (v.patch >= 0);
136+
117137
return v;
118138
}
119139

0 commit comments

Comments
 (0)