Improve std.conv.parse support for scope strings

This commit is contained in:
Dennis Korpel 2022-03-28 00:56:02 +02:00 committed by The Dlang Bot
parent 5f505267fa
commit 6ceeb18c82

View file

@ -2850,7 +2850,7 @@ do
static if (isNarrowString!Source) static if (isNarrowString!Source)
{ {
import std.string : representation; import std.string : representation;
auto s = source.representation; scope s = source.representation;
} }
else else
{ {
@ -2898,7 +2898,7 @@ do
} }
static if (isNarrowString!Source) static if (isNarrowString!Source)
source = cast(Source) s; source = source[$ - s.length .. $];
static if (doCount) static if (doCount)
{ {
@ -3105,7 +3105,7 @@ if (isSomeString!Source && !is(Source == enum) &&
* A $(LREF ConvException) if `source` is empty, if no number could be * A $(LREF ConvException) if `source` is empty, if no number could be
* parsed, or if an overflow occurred. * parsed, or if an overflow occurred.
*/ */
auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref scope Source source) auto parse(Target, Source, Flag!"doCount" doCount = No.doCount)(ref Source source)
if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum) && if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum) &&
isFloatingPoint!Target && !is(Target == enum)) isFloatingPoint!Target && !is(Target == enum))
{ {
@ -3115,18 +3115,17 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum
static if (isNarrowString!Source) static if (isNarrowString!Source)
{ {
import std.string : representation; import std.string : representation;
auto p = source.representation; scope p = source.representation;
} }
else else
{ {
alias p = source; alias p = source;
} }
void advanceSource() @trusted void advanceSource()
{ {
// p is assigned from source.representation above so the cast is valid
static if (isNarrowString!Source) static if (isNarrowString!Source)
source = cast(Source) p; source = source[$ - p.length .. $];
} }
static immutable real[14] negtab = static immutable real[14] negtab =