Skip to content

Commit 6dd50ba

Browse files
committed
Removed auto-decoding from the int with radix version of std.conv.parse
1 parent fd014e8 commit 6dd50ba

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

std/conv.d

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@ Lerr:
23472347
}
23482348

23492349
/// ditto
2350-
Target parse(Target, Source)(ref Source s, uint radix)
2350+
Target parse(Target, Source)(ref Source source, uint radix)
23512351
if (isSomeChar!(ElementType!Source) &&
23522352
isIntegral!Target && !is(Target == enum))
23532353
in
@@ -2360,13 +2360,23 @@ body
23602360
import std.exception : enforce;
23612361

23622362
if (radix == 10)
2363-
return parse!Target(s);
2363+
return parse!Target(source);
23642364

2365-
enforce!ConvException(!s.empty, "s must not be empty in integral parse");
2365+
enforce!ConvException(!source.empty, "s must not be empty in integral parse");
23662366

23672367
immutable uint beyond = (radix < 10 ? '0' : 'a'-10) + radix;
23682368
Target v = 0;
23692369

2370+
static if (isNarrowString!Source)
2371+
{
2372+
import std.string : representation, assumeUTF;
2373+
auto s = source.representation;
2374+
}
2375+
else
2376+
{
2377+
alias s = source;
2378+
}
2379+
23702380
do
23712381
{
23722382
uint c = s.front;
@@ -2395,6 +2405,9 @@ body
23952405
s.popFront();
23962406
} while (!s.empty);
23972407

2408+
static if (isNarrowString!Source)
2409+
source = s.assumeUTF;
2410+
23982411
return v;
23992412
}
24002413

0 commit comments

Comments
 (0)