Closed charlieMonroe closed 8 years ago
Hmm... I know what you mean...
Basically, the regex matching "precision" currently is: %[0-9]?\.?[0-9]+[fg]
(meaning: which are going to fall bac to the String(format: ...)
initializer.
Suggestions? (Apart from the example you mentioned I mean...)
Well, this isn't precision per sea, it's a padding formatting. Generally speaking C-style formatting can get really wild :)
See http://stackoverflow.com/a/29403060/1800936
According to this person, the regex for a placeholder is pretty insane.
For now, though, I believe that changing the regex to %[0-9.]+l?[fgid]
should be sufficient. But this is based on my needs - there certainly are people using much more complex formatting.
I can't see into your code, so I don't know if it's possible, but when converting such an expression, I'd suggest:
%[0-9a-zA-Z.]+
- notice the upper case letters included, since %02X
will convert the number into an upper-case hex (e.g. 2F
), which is often used.String(format: ...)
.String(format: ...)
initializer when it doesn't have to be used, rather than the opposite, thus creating a code that does something different.Well, this isn't precision per sea, it's a padding formatting.
Well, true... lol.
Thanks a lot for your input. I'm looking into it right now. ;-)
Marking the issue as fixed of the upcoming 2.4 - but I'll guess we'll have to re-visit. But... what can I say... that's what I'm here for... ;-)
Example:
NSString *statementID = [NSString stringWithFormat:@"%05li", (unsigned long)[file bankStatementID]];
Output:
var statementID: String = String(format: "%05li", CUnsignedLong(file.bankStatementID()))
Thanks for fixing the precision formatting, however, there are more format modifiers:
Currently gives:
Discarding the formatting completely. As mentioned before, I believe there should be a check of the number of formatting tokens in the format string and the number of arguments of the formatting method - and if they don't match, either throw an error, or fall back to the
String(format: ...)
initializer.