Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locale-specific integer formatting doesn't work on iOS #376

Closed
olliwang opened this issue Sep 6, 2016 · 4 comments
Closed

Locale-specific integer formatting doesn't work on iOS #376

olliwang opened this issue Sep 6, 2016 · 4 comments

Comments

@olliwang
Copy link

olliwang commented Sep 6, 2016

Hi, I was trying to print pretty integer on iOS. However, it seems std::setlocale() is not allowed in iOS (http://stackoverflow.com/questions/32594377/setlocale-works-in-ios-simulator-but-fails-on-device). Is it possible to provide other way to achieve this in iOS? Thanks.

@vitaut
Copy link
Contributor

vitaut commented Sep 6, 2016

The library doesn't use setlocale. Could you post the code and an error that you get on iOS?

@olliwang
Copy link
Author

olliwang commented Sep 6, 2016

I tried the following code as described in #305

std::setlocale(LC_ALL, "en_US.utf8");
fmt::print("cppformat: {:n}\n", 1234567);

However, the first line always returns NULL and the commas never printed.

@vitaut
Copy link
Contributor

vitaut commented Sep 6, 2016

I see. Since iOS doesn't seem to support locales, I guess you can provide your own imlementation of fmt::std::localeconv as it is done in format-test, something like:

namespace fmt {
namespace std {
lconv *localeconv() {
  static lconv lc = {...}; // initialize thousands_sep here
  return &lc;
}
}
}

@olliwang
Copy link
Author

olliwang commented Sep 6, 2016

Thanks @vitaut. This approach seems a bit tricky. Writing a custom function to add separators would be easier for me. However, it would be great if fmt can support iOS out-of-box.

@olliwang olliwang closed this as completed Sep 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants