Bug 24164 – readf should stop reading a trailing string at whitespace

Status
NEW
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-09-26T14:22:15Z
Last change time
2024-12-01T16:41:50Z
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: phobos#10532 →

Comments

Comment #0 by schveiguy — 2023-09-26T14:22:15Z
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.
Comment #1 by robert.schadek — 2024-12-01T16:41:50Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10532 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB