Skip to content

Commit

Permalink
Merge pull request #4597 from JackStouffer/parse-decoding
Browse files Browse the repository at this point in the history
Removed auto-decoding from std.conv.parse
  • Loading branch information
9il authored Jul 28, 2016
2 parents aa017e5 + 01010c5 commit ca1d015
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -2002,12 +2002,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 @@ -2016,10 +2020,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 @@ -2030,10 +2043,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 @@ -2043,7 +2065,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

0 comments on commit ca1d015

Please sign in to comment.