Bug 11231 – formattedRead accepts silently trailing space past the string to match, but no other character
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-11T20:06:00Z
Last change time
2017-07-21T04:05:34Z
Assigned to
nobody
Creator
thelastmammoth
Comments
Comment #0 by thelastmammoth — 2013-10-11T20:06:02Z
void main(){
string s = "abc:";
string a;
import std.format;
auto count=formattedRead(s, "%s: ", &a);
//works but should throw exception: Cannot find character ` ' in the input string
assert(a=="abc");
//NOTE: with any other character it seems to throw the exception, including "\n" and "\t"
}
Comment #1 by dlang-bugzilla — 2017-07-21T04:05:34Z
I believe formattedRead correctly mimics the behaviour of C's scanf function. See the documentation e.g. on http://www.cplusplus.com/reference/cstdio/scanf/.
The relevant part is:
> A single whitespace in the format string validates any quantity
> of whitespace characters extracted from the stream (including none).
Emphasis on "including none".
As such, I believe the behaviour is as expected, so I'm going to close this, but please reopen if you have a compelling argument to do so.