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

Improve std.format.formatValue #126

Merged
merged 14 commits into from Sep 4, 2011

Conversation

Projects
None yet
3 participants
@9rnsr
Member

9rnsr commented Jun 29, 2011

  • Issue 3813 - Bad writeln of arrays

    When string value is the element of an container, format it double-quoted like "...".
  • Issue 3890 - Bad writeln of a nested struct
  • Issue 5042 - format("%s") of struct without toString

    Add formatting like to!T().
  • Issue 5043 - writeln with empty arrays should write something useful

    Now empty range is formatted as "[]", including arrays and associative-arrays.
  • Issue 5237 - writefln doesn't respect Complex.toString

    Add conversion from FormatSpec!char("%.16f") to "%.16f".
  • Issue 5346 - instantiation of std.conv.toImpl and std.format.formatValue fails for unions

    When union object has toString, use it. Otherwise causes compile error.
  • (Unlisted) Support nested range formatting like "%({%(%02x %)} %)".
  • (Unlisted) Rewriting formatValue parameter 'ref FormatSpec!Char f' is breaks formatting.
  • (Unlisted) void[] was raw formatted, not like ubyte[].
@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Jul 3, 2011

Member

Add feature for quoting and escaping strings.

Member

9rnsr commented Jul 3, 2011

Add feature for quoting and escaping strings.

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Jul 4, 2011

Member

Escape C0 and C1 control code sets.

Member

9rnsr commented Jul 4, 2011

Escape C0 and C1 control code sets.

@9rnsr

View changes

Show outdated Hide outdated std/format.d Outdated
@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Jul 6, 2011

Member

Rebase and improve escaping.

  • Add functions for std.uni
    Based on general unicode category (Unicode 6.0.0), now we can check a character that is printable by isGraphical function. (By this addition, exe size has increased about +11KB.)
  • If a character is non-printable, it is formatted like '\xXX', '\uXXXX' or '\UXXXXXXXX'. And if formatted string contains invalid UTF sequence, whole string is formatted like HexString literal (e.g. x"XX XXXX XXXX XX ..."[cwd]).
Member

9rnsr commented Jul 6, 2011

Rebase and improve escaping.

  • Add functions for std.uni
    Based on general unicode category (Unicode 6.0.0), now we can check a character that is printable by isGraphical function. (By this addition, exe size has increased about +11KB.)
  • If a character is non-printable, it is formatted like '\xXX', '\uXXXX' or '\UXXXXXXXX'. And if formatted string contains invalid UTF sequence, whole string is formatted like HexString literal (e.g. x"XX XXXX XXXX XX ..."[cwd]).
@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 21, 2011

Does std.conv.to use std.format internally to convert string values to types at runtime? IOW, if hashes will now be printed as this:
["aaa":1, "bbb":2]

compared to the previous printing:
[aaa:1, bbb:2],

does it mean I'll be able to call:

Edit: Stupid implicit github formatting, I meant this:
http://codepad.org/qb5XL24n

ghost commented Jul 21, 2011

Does std.conv.to use std.format internally to convert string values to types at runtime? IOW, if hashes will now be printed as this:
["aaa":1, "bbb":2]

compared to the previous printing:
[aaa:1, bbb:2],

does it mean I'll be able to call:

Edit: Stupid implicit github formatting, I meant this:
http://codepad.org/qb5XL24n

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Jul 21, 2011

Member

Does std.conv.to use std.format internally to convert string values to types at runtime?

Now it is false, but I'd like to make it in the future.

Member

9rnsr commented Jul 21, 2011

Does std.conv.to use std.format internally to convert string values to types at runtime?

Now it is false, but I'd like to make it in the future.

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 21, 2011

Yeah, it would be cool if whatever you output via format can be converted back to its original type. Maybe in the future. :)

ghost commented Jul 21, 2011

Yeah, it would be cool if whatever you output via format can be converted back to its original type. Maybe in the future. :)

@DmitryOlshansky

This comment has been minimized.

Show comment
Hide comment
@DmitryOlshansky

DmitryOlshansky Aug 8, 2011

Member

Looking through diff for std.uni I see same tables I had to generate in my GSOC project (though I added more properties + blocks). But later on I switched to [a,b) intervals see https://github.com/blackwhale/FReD/blob/master/fred_uni.d
I then do binary search on it to find last element that is <= ch in it as an array of integers and check if it's odd:
https://github.com/blackwhale/FReD/blob/master/fred.d#L662
Checkout this nice Unicode datastructures presentation: http://macchiato.com/slides/Bits_of_Unicode.ppt
My 'Charset' is what they call inversion map, other then this I implemented 1-level trie as described there.
I plan to eventually add most common of it into std.uni ...
Any chance you can factor codepoint tables out into separate file, to avoid duplication with regex later on?
It will be internal file, something like e.g. __unitab.d (and fully auto generated).

Member

DmitryOlshansky commented Aug 8, 2011

Looking through diff for std.uni I see same tables I had to generate in my GSOC project (though I added more properties + blocks). But later on I switched to [a,b) intervals see https://github.com/blackwhale/FReD/blob/master/fred_uni.d
I then do binary search on it to find last element that is <= ch in it as an array of integers and check if it's odd:
https://github.com/blackwhale/FReD/blob/master/fred.d#L662
Checkout this nice Unicode datastructures presentation: http://macchiato.com/slides/Bits_of_Unicode.ppt
My 'Charset' is what they call inversion map, other then this I implemented 1-level trie as described there.
I plan to eventually add most common of it into std.uni ...
Any chance you can factor codepoint tables out into separate file, to avoid duplication with regex later on?
It will be internal file, something like e.g. __unitab.d (and fully auto generated).

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Aug 8, 2011

Member

My changes for std.uni is much ad-hoc. A better implementation would be welcomed.
Big-tables are internal ones, so it is possible to remove them later on.

It will be internal file, something like e.g. __unitab.d (and fully auto generated).

You can use std.internal.uni namespace if you hope. It is already used for std.bigint and std.mathspecial.

Member

9rnsr commented Aug 8, 2011

My changes for std.uni is much ad-hoc. A better implementation would be welcomed.
Big-tables are internal ones, so it is possible to remove them later on.

It will be internal file, something like e.g. __unitab.d (and fully auto generated).

You can use std.internal.uni namespace if you hope. It is already used for std.bigint and std.mathspecial.

@DmitryOlshansky

This comment has been minimized.

Show comment
Hide comment
@DmitryOlshansky

DmitryOlshansky Aug 9, 2011

Member

My changes for std.uni is much ad-hoc. A better implementation would be welcomed.
Big-tables are internal ones, so it is possible to remove them later on.

OK then if it's ad-hoc, I just thought you spent a lot of time on this one.

You can use std.internal.uni namespace if you hope. It is already used for std.bigint and std.mathspecial.

Right, we have std.internal for this.

Member

DmitryOlshansky commented Aug 9, 2011

My changes for std.uni is much ad-hoc. A better implementation would be welcomed.
Big-tables are internal ones, so it is possible to remove them later on.

OK then if it's ad-hoc, I just thought you spent a lot of time on this one.

You can use std.internal.uni namespace if you hope. It is already used for std.bigint and std.mathspecial.

Right, we have std.internal for this.

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Aug 10, 2011

Member

Add character escaping feature.

Member

9rnsr commented Aug 10, 2011

Add character escaping feature.

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Aug 11, 2011

Member

Does std.conv.to use std.format internally to convert string values to types at runtime?

Now it is false, but I'd like to make it in the future.

I just posted pull #183, and in it, changed almost to!String(value) implementation to use formatValue.

Member

9rnsr commented Aug 11, 2011

Does std.conv.to use std.format internally to convert string values to types at runtime?

Now it is false, but I'd like to make it in the future.

I just posted pull #183, and in it, changed almost to!String(value) implementation to use formatValue.

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Aug 23, 2011

Member

Rebased onto git master.

Member

9rnsr commented Aug 23, 2011

Rebased onto git master.

@andralex

This comment has been minimized.

Show comment
Hide comment
@andralex

andralex Sep 4, 2011

Member

OK, I made a pass and this is in good shape for committing. Please rebase. Thanks!

Member

andralex commented Sep 4, 2011

OK, I made a pass and this is in good shape for committing. Please rebase. Thanks!

@9rnsr

This comment has been minimized.

Show comment
Hide comment
@9rnsr

9rnsr Sep 4, 2011

Member

Rebased. Thank you for your good reviewing, Andrei.

Member

9rnsr commented Sep 4, 2011

Rebased. Thank you for your good reviewing, Andrei.

andralex added a commit that referenced this pull request Sep 4, 2011

Merge pull request #126 from 9rnsr/improve_format
Improve std.format.formatValue

@andralex andralex merged commit 4c8cbd2 into dlang:master Sep 4, 2011

kuettler pushed a commit to kuettler/phobos that referenced this pull request Feb 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment