| Thread overview | ||||||||
|---|---|---|---|---|---|---|---|---|
|
May 17, 2021 [Issue 21926] std.conv.octal(string) should allow leading zeros | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21926 --- Comment #1 from Witold Baryluk <witold.baryluk+d@gmail.com> --- This is being address in https://github.com/dlang/phobos/pull/8077 -- | ||||
May 17, 2021 [Issue 21926] Allow leading zeros in std.conv.octal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21926 Witold Baryluk <witold.baryluk+d@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|std.conv.octal(string) |Allow leading zeros in |should allow leading zeros |std.conv.octal -- | ||||
May 17, 2021 [Issue 21926] Allow leading zeros in std.conv.octal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21926 Dlang Bot <dlang-bot@dlang.rocks> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #2 from Dlang Bot <dlang-bot@dlang.rocks> --- @baryluk updated dlang/phobos pull request #8077 "Allow leadings zeros in std.conv.octal(string)" fixing this issue: - Fix issue 21926 - Allow leadings zeros in std.conv.octal 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`. https://github.com/dlang/phobos/pull/8077 -- | ||||
May 19, 2021 [Issue 21926] Allow leading zeros in std.conv.octal | ||||
|---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=21926 Dlang Bot <dlang-bot@dlang.rocks> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> --- dlang/phobos pull request #8077 "Fix issue 21926 - Allow leadings zeros in std.conv.octal(string)" was merged into master: - feeca84e51303a6eea71ae65c021285439adc53c by Witold Baryluk: Fix issue 21926 - Allow leadings zeros in std.conv.octal 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`. https://github.com/dlang/phobos/pull/8077 -- | ||||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply