liamnichols/xcstrings-tool

`%u` in format string produces `Int` argument

paulgessinger opened this issue ยท 5 comments

I would guess this should actually result in a UInt argument?

I'm guessing this is where this is currently decided:

case "d", "i", "o", "u", "x":
self = .int

Is there any argument why %u should not result in UInt or is this a bug?

Thanks for raising this @paulgessinger!

I would guess this should actually result in a UInt argument?

I've never worked with %u before, but looking at some reference for printf, it seems that you are right: https://en.wikipedia.org/wiki/Printf#Type_field

I think that it would be fine to add a uint case to PlaceholderType and map to it from "u" ๐Ÿ‘

If you feel up for a Pull Request, that would be great! If not, I'll take a look when I get a bit of free time ๐Ÿ™‚

In fact, it seems like "u", "x" and "o" should probably be UInt because sending a negative value using those placeholders results in the what I imagine is the wrong output:

let int: Int = -10

String(format: "%d", int) // -10
String(format: "%i", int) // -10
String(format: "%u", int) // 4294967286
String(format: "%x", int) // fffffff6
String(format: "%X", int) // FFFFFFF6
String(format: "%o", int) // 37777777766

let uint: UInt = 10

String(format: "%d", uint) // 10
String(format: "%i", uint) // 10
String(format: "%u", uint) // 10
String(format: "%x", uint) // a
String(format: "%X", uint) // A
String(format: "%o", uint) // 12

Happy to try a PR!

I'm struggling a bit to get the generated swift file since the test generator puts it in a temporary directory that gets deleted right after the test run it seems.

I tried changing the target location to CWD temporarily but that seems to give an empty for somehow.

EDIT: I found the teardown block...

Ah yes, I will have to try and remember how I implemented the testing infra ๐Ÿ˜… I'll add a note to write some instructions for future contributors ๐Ÿ™

Thanks again @paulgessinger, this is released in 0.1.1