weird formattedRead
frame
frame86 at live.com
Fri Apr 9 18:07:13 UTC 2021
On Friday, 9 April 2021 at 16:11:26 UTC, Oleg B wrote:
> Is space a special char for `formattedRead` and it simple stop
> parse without throwing exception if not found space (that
> represented in fmt string)?
> Have `formattedRead` any other special chars?
> Or it's bug?
I think it's a bug:
The char 0x20 is meant to be skipped till end of the string or a
parseable char in the format string by the function
readUpToNextSpec().
If the function found a whitespace in the input string, it's fine
and skipped as long there is another whitespace char. But if the
input string range is already done, it also does just nothing
anymore. For other chars if would throw the 'Cannot find
character' exception.
But the source declared this as "backwards compatibility":
```
string s = " 1.2 3.4 ";
double x, y, z;
assert(formattedRead(s, " %s %s %s ", &x, &y, &z) == 2);
assert(s.empty);
assert(approxEqual(x, 1.2));
assert(approxEqual(y, 3.4));
assert(isNaN(z));
```
So it seems to be a desired behaviour.
More information about the Digitalmars-d-learn
mailing list