[Issue 24164] New: readf should stop reading a trailing string at whitespace
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Sep 26 14:22:15 UTC 2023
https://issues.dlang.org/show_bug.cgi?id=24164
Issue ID: 24164
Summary: readf should stop reading a trailing string at
whitespace
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: schveiguy at gmail.com
scanf for strings stops at whitespace. readf does not.
This shouldn't be too much of a problem, because the %s could be followed by
something else, and that match would eagerly go to the next thing.
But for a trailing %s, with a string as the target, the result is that string
is filled with the *rest of the stream*. That makes no sense, and is a land
mine for people who aren't familiar with readf. Not only that, but using readf
to consume the rest of the file into a string doesn't seem like a great use
case to support.
I propose that readf, when presented with a format that ends in %s, and whose
matching type is a string, should stop when a whitespace character is
encountered.
I know this is an inconsistency and special case. It could be done potentially
in a way to avoid special cases (like send to the processing function a boolean
saying nothing is left in the format string), but it should be done this way.
Alternatively, this could be considered a runtime error.
--
More information about the Digitalmars-d-bugs
mailing list