Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Apr 26, 2014

@ghost
Copy link
Author

ghost commented Apr 26, 2014

std.uni seems to use a lot of magical things like opDispatch so I couldn't figure out which script has only a few intervals, I picked Cyrillic almost randomly. Is there a script that has just a few intervals so it looks nicer in the documented unittest?

@monarchdodra
Copy link
Collaborator

Somewhat related, but do we have any flags to say "show base"? Seems like it would be useful here.

std/uni.d Outdated
Copy link
Collaborator

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 :/

Copy link
Author

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.

Copy link
Collaborator

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.

@ghost
Copy link
Author

ghost commented Apr 28, 2014

What do you mean by "show base"?

@monarchdodra
Copy link
Collaborator

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:

Value: [    5]
Value: [  0x5]

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:

[0x0030..0x5000)

Now... how to customise space or not around the .. ? Just kidding :D

@ghost
Copy link
Author

ghost commented Apr 29, 2014

What's sad is that:

writefln("%#x", 0xabcd);
writefln("%#X", 0xabcd);

Prints:

0xabcd
0XABCD

But there's no 0xABCD. IOW keep the small x. Is this a bug or deliberate behavior?

@ghost
Copy link
Author

ghost commented Apr 29, 2014

Thanks for letting me know about being able to reuse fmt. I didn't know about this, so I've added it to this page: http://wiki.dlang.org/Defining_custom_print_format_specifiers#Re-using_existing_formatting_tools

@monarchdodra
Copy link
Collaborator

What's sad is that:

I think it's a bug. I've never head of 0XABCD before.

@ghost
Copy link
Author

ghost commented Apr 29, 2014

In the meantime is this good to go? I admit I don't like the duplicated code block there.

@monarchdodra
Copy link
Collaborator

In the meantime is this good to go?

The only thing I have doubts about is the 0X test, since I think it's a bug. I don't know if it's better to leave it in, and fix it later, or comment it out completely.

I admit I don't like the duplicated code block there.

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 toString on the Interval object itself. I wish I could say that there is then a "cool range formatting trick", such as:

formattedWrite(sink, "%(µs %)", range);

But the truth is that I have been unable to "feed" the fmt flags back into the loop with that...

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)
                }
            }

@ghost
Copy link
Author

ghost commented Apr 30, 2014

Updated.

std/uni.d Outdated
Copy link
Collaborator

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.

monarchdodra added a commit that referenced this pull request May 4, 2014
Issue 12184 - Implement advanced formatting support for std.uni.InversionList
@monarchdodra monarchdodra merged commit 7872022 into dlang:master May 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants