Bug 9558 – 0b and 0x prefixes for std.string.isNumeric
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-02-21T09:52:00Z
Last change time
2015-09-18T08:53:17Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2013-02-21T09:52:31Z
This is almost an enhancement request.
I think std.string.isNumeric should see the 0b and 0x prefixes as parts of a number literal:
import std.stdio: writeln;
import std.string: isNumeric;
void main() {
isNumeric("0x10").writeln();
isNumeric("0b1010101").writeln();
}
With dmd 2.062 prints:
false
false
Expected:
true
true
Comment #1 by hsteoh — 2015-09-08T17:45:29Z
I'm not sure about this. The '0x', '0b', etc., prefixes are syntax defined by programming languages, whereas isNumeric is intended to check user input. Presumably, most users wouldn't know what 0x, 0b, etc., are, and may be surprised to learn that what they consider as invalid input (e.g. 0b10) is actually accepted by the program, with results that are unexpected to them.
Parsing programming language literals should not be conflated with parsing user input.
Comment #2 by bearophile_hugs — 2015-09-18T08:53:17Z
(In reply to hsteoh from comment #1)
> I'm not sure about this. The '0x', '0b', etc., prefixes are syntax defined
> by programming languages, whereas isNumeric is intended to check user input.
> Presumably, most users wouldn't know what 0x, 0b, etc., are, and may be
> surprised to learn that what they consider as invalid input (e.g. 0b10) is
> actually accepted by the program, with results that are unexpected to them.
>
> Parsing programming language literals should not be conflated with parsing
> user input.
OK, I close this down.