[Issue 19982] New: padLeft usability issues
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jun 18 21:02:55 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19982
Issue ID: 19982
Summary: padLeft usability issues
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: sgrammer at economicmodeling.com
padLeft appears to be implicitly converting the input string into an array of
uints. The documentation mentions using byGrapheme, but the compiler can't
handle it.
---------------------------------------------------
import std.range : padLeft;
import std.stdio : writeln;
import std.uni : byGrapheme;
import std.array : array;
void main()
{
string s = "a string";
writeln(s.padLeft('0', 10)); // [48, 48, 97, 32, 115, 116, 114, 105, 110,
103]
writeln("a string".padLeft('0', 10)); // [48, 48, 97, 32, 115, 116, 114,
105, 110, 103]
writeln("a string".padLeft(dchar('0'), 10)); // "00a string" (correct!)
// example directly from the documentation
writeln("abc".padLeft('_', 6)); // [95, 95, 95, 97, 98, 99]
// Error: template std.range.padLeft cannot deduce function from argument
types !()(Result!string, char, int)
// writeln(byGrapheme("abc").padLeft('_', 6));
// Error: template std.range.padLeft cannot deduce function from argument
types !()(Grapheme[], char, int),
// writeln(byGrapheme("abc").array.padLeft('_', 6));
}
--
More information about the Digitalmars-d-bugs
mailing list