mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 22:50:38 +03:00
![]() First of all, the DDoc currently says that: "Leading zero is allowed, but not required." The current implementation doesn't respect that. D lexer allows leading zero(s) also. And when considering octal from string, there is no possibility of confusion, as the comments in the code claim. Disallowing leading zeros for octal conversion from string, does not help with anything actually. So lets allow leading zeros. Allowing leading zeros, does help when implementing various APIs (i.e. glibc, Linux kernel), where a lot of octal constant, are defined with multiple leading zeros, for readability and alignment, in C headers. Having to manually or automatically special case these when porting such API definitions, is counter-productive. Example from a Linux kernel (`include/uapi/linux/stat.h`): ```c #define S_IFMT 00170000 #define S_IFSOCK 0140000 #define S_IFLNK 0120000 #define S_IFREG 0100000 #define S_IFBLK 0060000 #define S_IFDIR 0040000 #define S_IFCHR 0020000 #define S_IFIFO 0010000 #define S_ISUID 0004000 #define S_ISGID 0002000 #define S_ISVTX 0001000 ``` With this patch, now it is trivial and easier to convert these to D: ```d ... enum S_ISVTX = octal!"0001000"; ``` while being close to original. That helps with readability, and long term maintenance. In fact the run-time version provided by `parse!(int)(string, 8)` also supports leading zeros already. So this makes `octal` more consistent `parse`. |
||
---|---|---|
.. | ||
algorithm | ||
container | ||
datetime | ||
digest | ||
experimental | ||
format | ||
internal | ||
math | ||
net | ||
range | ||
regex | ||
uni | ||
windows | ||
array.d | ||
ascii.d | ||
base64.d | ||
bigint.d | ||
bitmanip.d | ||
compiler.d | ||
complex.d | ||
concurrency.d | ||
conv.d | ||
csv.d | ||
demangle.d | ||
encoding.d | ||
exception.d | ||
file.d | ||
functional.d | ||
getopt.d | ||
json.d | ||
mathspecial.d | ||
meta.d | ||
mmfile.d | ||
numeric.d | ||
outbuffer.d | ||
package.d | ||
parallelism.d | ||
path.d | ||
process.d | ||
random.d | ||
signals.d | ||
socket.d | ||
stdint.d | ||
stdio.d | ||
string.d | ||
sumtype.d | ||
system.d | ||
traits.d | ||
typecons.d | ||
typetuple.d | ||
uri.d | ||
utf.d | ||
uuid.d | ||
variant.d | ||
xml.d | ||
zip.d | ||
zlib.d |