parseNoGC can work with code points directly.
This commit is contained in:
parent
6e1239fdac
commit
cac25207f1
|
@ -24,7 +24,7 @@ import std.range;
|
||||||
Target parseNoGC(Target, Source)(ref Source s, uint radix, out bool overflow)
|
Target parseNoGC(Target, Source)(ref Source s, uint radix, out bool overflow)
|
||||||
@safe pure nothrow @nogc
|
@safe pure nothrow @nogc
|
||||||
if (isSomeChar!(ElementType!Source) &&
|
if (isSomeChar!(ElementType!Source) &&
|
||||||
isIntegral!Target && !is(Target == enum))
|
isIntegral!Target && !is(Target == enum))
|
||||||
in { assert(radix >= 2 && radix <= 36); }
|
in { assert(radix >= 2 && radix <= 36); }
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -33,10 +33,15 @@ body
|
||||||
Target v = 0;
|
Target v = 0;
|
||||||
size_t atStart = true;
|
size_t atStart = true;
|
||||||
|
|
||||||
for (; !s.empty; s.popFront())
|
// We can safely foreach over individual code points.
|
||||||
|
// Even with UTF-8 any digit is ASCII and anything not ASCII (such as the start of
|
||||||
|
// a UTF-8 sequence) is not a digit.
|
||||||
|
foreach(i; 0 .. s.length)
|
||||||
{
|
{
|
||||||
uint c = s.front;
|
dchar c = s[i];
|
||||||
if (c < '0')
|
// We can just take a char instead of decoding because anything non-ASCII is not
|
||||||
|
// going to be a decodable digit, i.e. we will end at such a byte.
|
||||||
|
if (c < '0' || c >= 0x80)
|
||||||
break;
|
break;
|
||||||
if (radix < 10)
|
if (radix < 10)
|
||||||
{
|
{
|
||||||
|
@ -67,7 +72,7 @@ body
|
||||||
|
|
||||||
|
|
||||||
/// Buils a message to a buffer similarly to writef/writefln, but without
|
/// Buils a message to a buffer similarly to writef/writefln, but without
|
||||||
/// using GC.
|
/// using GC.
|
||||||
///
|
///
|
||||||
/// C snprintf would be better, but it isn't pure.
|
/// C snprintf would be better, but it isn't pure.
|
||||||
/// formattedWrite isn't completely @nogc yet (although it isn't GC-heavy).
|
/// formattedWrite isn't completely @nogc yet (although it isn't GC-heavy).
|
||||||
|
|
Loading…
Reference in a new issue