tfc / pprintpp

Typesafe Python Style Printf Formatting for C++
MIT License
233 stars 12 forks source link

Grouping #6

Closed ghost closed 5 years ago

ghost commented 5 years ago

fmtlib offers grouping:

setlocale(LC_NUMERIC, "en_US.UTF-8");
fmt::print("{:n}", 45000); // prints "45,000"

https://github.com/fmtlib/fmt

tfc commented 5 years ago

Hello @cup, thank you for opening an issue. Unfortunately, i don't know what to do with your comment.

Do you wish to have grouping support in pprintpp, too? If so, please understand that pprintpp is only a frontend for whatever printf implementation you use. That means, that if your printf implementation has no grouping support, then pprintpp will not be able to change that as it is not designed to do that.

Or do you have a printf implementation that supports grouping, but it does not work well in combination with pprintpp? If yes, and you wish for assistance fixing that, then i can help you best if you provide the exact format schema that pprintpp would need to generate from given inputs.

ghost commented 5 years ago

@tfc for the purpose of this issue, lets assume that all printf have grouping support. Now thats settled, how to do grouping with pprintpp?

tfc commented 5 years ago

Hey @cup,

i just looked up how grouping in POSIX printf works:

#include <locale.h>
#include <stdio.h>

int main() {
    setlocale(LC_ALL, ""); /* use user selected locale */
    printf("%'d", 1000000);
}

with pprintpp it works out of the box:

#include <pprintpp.hpp>

#include <clocale>
#include <cstdio>

int main() {
    setlocale(LC_ALL, ""); /* use user selected locale */
    pprintf("{'}", 1000000);
}

In both cases, the output is 1,000,000.