Fix %*s handling by formattedRead() (#10654)

This commit is contained in:
Nicolò Monaldini 2025-03-02 23:59:08 +01:00 committed by GitHub
parent 4b39202045
commit 0d724aa0c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View file

@ -24,7 +24,7 @@ package(std.format):
void skipData(Range, Char)(ref Range input, scope const ref FormatSpec!Char spec)
{
import std.ascii : isDigit;
import std.ascii : isDigit, isWhite;
import std.range.primitives : empty, front, popFront;
switch (spec.spec)
@ -33,6 +33,9 @@ void skipData(Range, Char)(ref Range input, scope const ref FormatSpec!Char spec
case 'd':
if (input.front == '+' || input.front == '-') input.popFront();
goto case 'u';
case 's':
while (!input.empty && !isWhite(input.front)) input.popFront();
break;
case 'u':
while (!input.empty && isDigit(input.front)) input.popFront();
break;

View file

@ -377,6 +377,16 @@ if (!isType!fmt && isSomeString!(typeof(fmt)))
assert(t[0] == 1 && t[1] == 2.125);
}
@safe pure unittest
{
string hello;
string world;
assert("hello ignore world".formattedRead("%s %*s %s", hello, world) == 2);
assert(hello == "hello");
assert(world == "world");
}
// https://issues.dlang.org/show_bug.cgi?id=23600
@safe pure unittest
{