Two possibilities of fixing format problem, which is better?
dlang at d-ecke.de
Wed Oct 23 14:45:51 UTC 2019
On Tuesday, 22 October 2019 at 17:12:53 UTC, H. S. Teoh wrote:
> IMO, yes. When you write "%20s" you're essentially saying
> "format the next argument as a string with width 20". It's
> unexpected behaviour for the width to suddenly apply to
> elements within the object as opposed to the object itself.
While trying to implement this I came across a function called
formatElement. Next to this there is a comment saying
"undocumented because of deprecation". Does anyone know about
this "deprecation" of formatElement? It's used inside std.format,
e.g. for formating ranges. And it appears in one public example,
where it probably should not appear.
The reason I'm asking is, that I'd like to get the following
int a = [-5, 345];
string t1 = format("[%10s] [%-10s]", a, a);
assert(t1 == "[ [-5, 345]] [[-5, 345] ]");
So far I managed to do this, but now an other unittest pops up,
formatTest( [cast(string)"hello"], `["hello"]` );
This is essentially, because the old implementation called
formatElement, while the new one doesn't. Looking inside
formatElement, this function formats the element not according to
some %... parameter, but similar to how it would be presented as
a litteral in source code.
Now I'm unsure, how to continue.
More information about the Digitalmars-d