Question

Can I make all std::string in my application support Unicode with Boost.Locale? After reading the documentation I can say yes. But I don't understand how it works. The main question is can I still use boost string algorithms library or Boost.Lexical_Cast libraries? If yes, why I need boost::locale::to_upper and similar format methods, if I have these methods in boost string algorithm library.

Was it helpful?

Solution

Yes, you can make all strings in your application Unicode encoded with Boost.Locale.

To make it work you imbue the locale into the string, or set the default global locale to your new unicode-based locale (generated by Boost.Locale). See here for how to do that: http://www.boost.org/libs/locale/doc/html/locale_gen.html and http://www.boost.org/libs/locale/doc/html/faq.html

The string manipulation APIs in Boost.Locale are different to the ones provided in the Boost string algorithm library. See here for why the Boost.Locale functions are better: http://www.boost.org/libs/locale/doc/html/conversions.html

You can still use boost::lexical_cast, provided you set the global locale correctly (as, if I recall correctly, you can't explicitly pass a locale object to Boost.LexicalCast).

Keep in mind however that this will 'break' some cases, for example, when converting an integer to a string, instead of using the C locale (as was probably your previous default), it will use a different one, which may insert separators etc. When doing conversions that are NOT displayed to the user, you may wish to use std::stringstream et al directly to avoid these unwanted formatting changes.

I highly suggest you read the Boost.Locale documentation in full, as it should address most of your concerns (especially the FAQ, generation backend information, etc.).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top