From 6ceeb18c8283ec12957d888c06d05dd2ce2bd5a2 Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Mon, 28 Mar 2022 00:56:02 +0200 Subject: [PATCH] Improve `std.conv.parse` support for `scope` strings --- std/conv.d | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/std/conv.d b/std/conv.d index d0bc243f2..8f6c3bf56 100644 --- a/std/conv.d +++ b/std/conv.d @@ -2850,7 +2850,7 @@ do static if (isNarrowString!Source) { import std.string : representation; - auto s = source.representation; + scope s = source.representation; } else { @@ -2898,7 +2898,7 @@ do } static if (isNarrowString!Source) - source = cast(Source) s; + source = source[$ - s.length .. $]; 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 * 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) && isFloatingPoint!Target && !is(Target == enum)) { @@ -3115,18 +3115,17 @@ if (isInputRange!Source && isSomeChar!(ElementType!Source) && !is(Source == enum static if (isNarrowString!Source) { import std.string : representation; - auto p = source.representation; + scope p = source.representation; } else { alias p = source; } - void advanceSource() @trusted + void advanceSource() { - // p is assigned from source.representation above so the cast is valid static if (isNarrowString!Source) - source = cast(Source) p; + source = source[$ - p.length .. $]; } static immutable real[14] negtab =