dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.98k stars 4.66k forks source link

UTF8Formatter is inconsistent with and more limited than the utf16 formatting support #67962

Open tannergooding opened 2 years ago

tannergooding commented 2 years ago

As raised in https://github.com/dotnet/runtime/pull/67959#discussion_r849654971, the Utf8Formatter appears to be first and foremost inconsistent with T.ToString(string format) for the formats it does support.

For example, it currently throws if any precision specifier is given for G where-as int.ToString("G99") is completely valid.

It appears as though integers are missing support for C, E, F, and P.

Floating-point more broadly (meaning including for utf16 formatting) doesn't support D either, but reasonably could (its basically just an alternative to F0).

It looks like floating-point just forwards down to the utf16 formatter and so it appears to support the same set. This is, however, less efficient and should likely be looked at since we actually have a correct interim UTF8 buffer for the digits that are built up.

dotnet-issue-labeler[bot] commented 2 years ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

ghost commented 2 years ago

Tagging subscribers to this area: @dotnet/area-system-runtime See info in area-owners.md if you want to be subscribed.

Issue Details
As raised in https://github.com/dotnet/runtime/pull/67959#discussion_r849654971, the `Utf8Formatter` appears to be first and foremost inconsistent with `T.ToString(string format)` for the formats it does support. For example, it currently throws if any precision specifier is given for `G` where-as `int.ToString("G99")` is completely valid. It appears as though integers are missing support for `C`, `E`, `F`, and `P`. `Floating-point` more broadly (meaning including for `utf16` formatting) doesn't support `D` either, but reasonably could (its basically just an alternative to `F0`). It looks like `floating-point` just forwards down to the utf16 formatter and so it appears to support the same set. This is, however, less efficient and should likely be looked at since we actually have a correct interim UTF8 buffer for the digits that are built up.
Author: tannergooding
Assignees: -
Labels: `area-System.Runtime`, `untriaged`
Milestone: -