Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::locale::to_lower throw bad_cast exception

Boost 1.54 x64 on Win 7 64bits and VS2010. Compiling as "Release x64" and running the following code:

#include <boost/locale/conversion.hpp>
std::wstring y = L"NoNseNSE";
std::wstring w = boost::locale::to_lower(y);

throw std::bad_cast exception. Nothing changes even after adding (as suggested elsewhere):

std::locale mylocale("");
std::locale::global(mylocale);

or changing to_lower(y) to: to_lower(y, mylocale) or using std::string instead of std::wstring or setting LANG in the environment.

The goal is to convert to lowercase Italian UTF-8 words. I don't have found around problems like this, so I presume it is my machine specific problem or a boost library problem. BTW I have downloaded the precompiled boost library (boost_1_54_0-msvc-10.0-64.exe) from sourceforge. Any idea? Thanks! mario

like image 299
SiliconValley Avatar asked Feb 14 '23 19:02

SiliconValley


1 Answers

This exception is thrown when your locale passed to boost::locale::to_lower (by default std::locale(), that is a copy of the global locale) does not have a boost::locale::converter facet installed. See this for the related documentation.

Use a boost::locale::generator to create the locale instead. (See also the examples linked to by the documentation, for example this one.)

like image 66
Aleph Avatar answered Feb 23 '23 23:02

Aleph