Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Reduce code size of parseoptions.parse!int()
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel committed Jun 20, 2022
1 parent 15f69b5 commit 2642c08
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/core/internal/parseoptions.d
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ inout(char)[] find(alias pred)(inout(char)[] str)
}

bool parse(T : size_t)(const(char)[] optname, ref inout(char)[] str, ref T res, const(char)[] errName, bool mayHaveSuffix = false)
if (is(T == size_t))
in { assert(str.length); }
do
{
Expand Down Expand Up @@ -242,6 +243,22 @@ do
if (v > res.max)
return parseError("a number " ~ T.max.stringof ~ " or below", optname, str[0 .. i], errName);
str = str[i .. $];
res = v;
return true;
}

bool parse(T : size_t)(const(char)[] optname, ref inout(char)[] str, ref T res, const(char)[] errName, bool mayHaveSuffix = false)
if (!is(T == size_t))
in { assert(str.length); }
do
{
const oldStr = str;
size_t v;
if (!parse!size_t(optname, str, v, errName, mayHaveSuffix))
return false;

if (v > res.max)
return parseError("a number " ~ T.max.stringof ~ " or below", optname, oldStr[0 .. $-str.length], errName);
res = cast(T) v;
return true;
}
Expand Down

0 comments on commit 2642c08

Please sign in to comment.