Skip to content

Commit ca1d015

Browse files
authored
Merge pull request #4597 from JackStouffer/parse-decoding
Removed auto-decoding from std.conv.parse
2 parents aa017e5 + 01010c5 commit ca1d015

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

std/conv.d

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,12 +2002,16 @@ Target parse(Target, Source)(ref Source s)
20022002
enum bool sign = 0;
20032003

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

20072007
if (s.empty)
20082008
goto Lerr;
20092009

2010-
c = s.front;
2010+
static if (isAutodecodableString!Source)
2011+
c = s[0];
2012+
else
2013+
c = s.front;
2014+
20112015
static if (Target.min < 0)
20122016
{
20132017
switch (c)
@@ -2016,10 +2020,19 @@ Target parse(Target, Source)(ref Source s)
20162020
sign = true;
20172021
goto case '+';
20182022
case '+':
2019-
s.popFront();
2023+
static if (isAutodecodableString!Source)
2024+
s = s[1 .. $];
2025+
else
2026+
s.popFront();
2027+
20202028
if (s.empty)
20212029
goto Lerr;
2022-
c = s.front;
2030+
2031+
static if (isAutodecodableString!Source)
2032+
c = s[0];
2033+
else
2034+
c = s.front;
2035+
20232036
break;
20242037

20252038
default:
@@ -2030,10 +2043,19 @@ Target parse(Target, Source)(ref Source s)
20302043
if (c <= 9)
20312044
{
20322045
Target v = cast(Target)c;
2033-
s.popFront();
2046+
2047+
static if (isAutodecodableString!Source)
2048+
s = s[1 .. $];
2049+
else
2050+
s.popFront();
2051+
20342052
while (!s.empty)
20352053
{
2036-
c = cast(typeof(c)) (s.front - '0');
2054+
static if (isAutodecodableString!Source)
2055+
c = cast(typeof(c)) (s[0] - '0');
2056+
else
2057+
c = cast(typeof(c)) (s.front - '0');
2058+
20372059
if (c > 9)
20382060
break;
20392061

@@ -2043,7 +2065,11 @@ Target parse(Target, Source)(ref Source s)
20432065
// Note: `v` can become negative here in case of parsing
20442066
// the most negative value:
20452067
v = cast(Target) (v * 10 + c);
2046-
s.popFront();
2068+
2069+
static if (isAutodecodableString!Source)
2070+
s = s[1 .. $];
2071+
else
2072+
s.popFront();
20472073
}
20482074
else
20492075
throw new ConvOverflowException("Overflow in integral conversion");

0 commit comments

Comments
 (0)