-
-
Notifications
You must be signed in to change notification settings - Fork 746
Issue 12184 - Implement advanced formatting support for std.uni.InversionList #2126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
|
Somewhat related, but do we have any flags to say "show base"? Seems like it would be useful here. |
std/uni.d
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum... this only takes into account the "type" falg, but discards everything else (say, padding and whatnot). I think: something along the lines of:
FormatSpec!char fmt2 = fmt;
put(sink, "[");
formatValue(sink, val.a, fmt);
put(sink, "..");
formatValue(sink, val.b, fmt2);
put(sink, ")");This is more generic and robust (I think): In particular, it handles explicit width for those with OCD that want alignment. Unfortunately, it doesn't work so well for handling the display of the base :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I haven't worked with other fmt options yet so I managed to forget about these. I'll have a look at this tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I haven't worked with other fmt options yet so I managed to forget about these.
Well, what I mean is that (ideally) you shouldn't have to be re-inventing an Fmt to "format string" decoder. Just use the fmt straight up.
|
What do you mean by "show base"? |
I meant that it is the fomat flag that should choose wether or not to display "0x". In any case, I found it, it's '#'. EG: writefln("Value: [%5x]", 23);
writefln("Value: [%#5x]", 23);Prints: So, if I have an inversion list, and if you use my code, you should be able to get: writefln("%#06X", InversionList(0x30, 0x5000));prints: Now... how to customise space or not around the |
|
What's sad is that: writefln("%#x", 0xabcd);
writefln("%#X", 0xabcd);Prints: But there's no |
|
Thanks for letting me know about being able to reuse |
I think it's a bug. I've never head of |
|
In the meantime is this good to go? I admit I don't like the duplicated code block there. |
The only thing I have doubts about is the
When you want to loop "with a separator", you can avoid duplicate code with a loop with customized control: if (!range.empty)
for ( ; ; )
{
//Process body
range.popFront();
if (range.empty) return;
//Process separator
} Another option, is to add the formattedWrite(sink, "%(µs %)", range);But the truth is that I have been unable to "feed" the In any case, the code can then becomes pretty simple (copied almost verbatim from format): if (!val.empty)
{
formatElement(sink, range.front, fmt);
range.popFront();
foreach (i; range)
{
put(w, " ");
formatElement(sink, i, fmt)
}
} |
|
Updated. |
std/uni.d
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, but this comment isn't quite accurate anymore. Something simpler along the lines of "The formating flag is applied individually to each value" should do.
Issue 12184 - Implement advanced formatting support for std.uni.InversionList
https://issues.dlang.org/show_bug.cgi?id=12184