Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -2003,12 +2003,16 @@ Target parse(Target, Source)(ref Source s)
enum bool sign = 0;

enum char maxLastDigit = Target.min < 0 ? 7 : 5;
Unqual!(typeof(s.front)) c;
uint c;

if (s.empty)
goto Lerr;

c = s.front;
static if (isAutodecodableString!Source)
c = s[0];
else
c = s.front;

static if (Target.min < 0)
{
switch (c)
Expand All @@ -2017,10 +2021,19 @@ Target parse(Target, Source)(ref Source s)
sign = true;
goto case '+';
case '+':
s.popFront();
static if (isAutodecodableString!Source)
s = s[1 .. $];
else
s.popFront();

if (s.empty)
goto Lerr;
c = s.front;

static if (isAutodecodableString!Source)
c = s[0];
else
c = s.front;

break;

default:
Expand All @@ -2031,10 +2044,19 @@ Target parse(Target, Source)(ref Source s)
if (c <= 9)
{
Target v = cast(Target)c;
s.popFront();

static if (isAutodecodableString!Source)
s = s[1 .. $];
else
s.popFront();

while (!s.empty)
{
c = cast(typeof(c)) (s.front - '0');
static if (isAutodecodableString!Source)
c = cast(typeof(c)) (s[0] - '0');
else
c = cast(typeof(c)) (s.front - '0');

if (c > 9)
break;

Expand All @@ -2044,7 +2066,11 @@ Target parse(Target, Source)(ref Source s)
// Note: `v` can become negative here in case of parsing
// the most negative value:
v = cast(Target) (v * 10 + c);
s.popFront();

static if (isAutodecodableString!Source)
s = s[1 .. $];
else
s.popFront();
}
else
throw new ConvOverflowException("Overflow in integral conversion");
Expand Down