c42f / tinyformat

Minimal, type safe printf replacement library for C++
537 stars 75 forks source link

Add POSIX extension for positional arguments #45

Closed jrohel closed 5 years ago

jrohel commented 6 years ago

The ability to rearrange formatting arguments is an important feature for localization because the word order may vary in different languages.

Without this we can't use tinyformat in projects where localization is required.

Example of reordering arguments in date (American to Germany format): tfm::printf("%1$s, %3$d. %2$s, %4$d:%5$.2d\n", weekday, month, day, hour, min);

nigels-com commented 6 years ago

Interesting. I'll run this through some test coverage...

c42f commented 6 years ago

@jrohel Thanks, it's great to have this! The posix syntax is something I've always thought would be nice to support but I've never had a reason to implement it myself. In fact, argument reordering is one of the main reasons I implemented the type-opaque FormatArg wrapper stuff, and I'm pleased to see it allowed you to slot this in very neatly.

I probably won't have time to look at this closely for the next few days. At a quick glance it looks quite clean. One minor quibble - I'd appreciate it if you could reformat the braces to match the ambient style.

jrohel commented 6 years ago

@c42f Ok. I changed the PR.

pip010 commented 6 years ago

what is the status of this PR ? quite a handy feature but still open since last year !?

c42f commented 5 years ago

Thanks for the changes (all those months ago). Let's get this old thing over the line; I added a small refactoring which factors out some of the new code and adds a couple of tests.