Repository navigation
strformat: the fill character is no longer uppercased by the uppercase float types - #26894
Merged
Merged
Conversation
…t types
`E`, `F` and `G` are documented as converting the number to uppercase, but formatFloat applied toUpperAscii to the aligned string, so the fill character was uppercased as well: `&"{2.5:x>10.1F}"` gave `XXXXXXX2.5` instead of `xxxxxxx2.5`. Integers are not affected because formatInt never touches the fill.
Uppercase the formatted number before aligning it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
strformatdocumentsEas "Exponent notation. Same aseexcept it convertsthe number to uppercase", and
Flikewise forf.formatFloatinstead appliestoUpperAsciito the aligned string, so the fill character is uppercased too(
Ggoes through the same code path):Integers go through
formatInt, which never touches the fill, so the two numberkinds disagree today. Python, whose f-strings this module's syntax is modelled on,
keeps the fill as written (
format(2.5, 'x>10.1F')is'xxxxxxx2.5').The fix uppercases
f(the formatted number) before aligning it, instead ofuppercasing the aligned result. The output is unchanged whenever the fill is not
a lowercase ASCII letter, so zero padding and space padding are unaffected.
Tests
A new block in
tests/stdlib/tstrformat.nim; that file runsmain()both in theVM (
static: main()) and at runtime, and the bug was present in both.Run on Linux x86_64 with the compiler that
./build_all.shproduces from thischeckout.
koch boothad not finished on that machine, so these runs usedbin/nimfromcsources_v4(Nim 2.4.0) together with this checkout'slib/:git diff --checkis clean. A regex scan of{...}format literals inlib/andtests/turned up no other assertion that formats a float with an uppercase typeand an explicit fill character.
#26849 touches the same proc (the zero-padding sign check a few lines above) but
the two changes are independent and the hunks do not overlap.
This PR was prepared with AI assistance (Claude).