Boost logo

Boost :

From: Gleb Igumnov (crazy.sage_at_[hidden])
Date: 2022-08-19 04:35:11


Hello. I have a problem. I need to get std::locale object for my locale
(ru_RU.UTF-8) on a systems that don't have one. I decided to take a look at
boost::locale::generator, as it has ICU as a backend and there must be full
locale info in it. But to my surprise generator do not generate only locale
facet that I really need - ctype one. For example following code will go
"oops" branch:

#include <iostream>
#include <boost/locale.hpp>
#include <boost/locale/localization_backend.hpp>

using namespace std;

int main()
{
    using namespace boost::locale;
    localization_backend_manager my = localization_backend_manager::global();
    my.select("icu");

    // I know that icu is default backend but I select it explicitly to be sure.
    boost::locale::generator gen(my);
    std::locale loc( gen.generate( "ru_RU.UTF-8" ) );
    if( !std::isalpha( L'Ñ„', loc ) )
       std::cout<< "Oops\n";
    else
       std::cout << "Ok\n";
    return 0;
}

But if I will do

    std::locale loc( gen.generate( std::locale( "en_US.UTF-8" ),
"ru_RU.UTF-8" ) );

It will work, as it will have ctype facet from en_US.UTF-8 locale, but that
is not a solution as I may not have en_US.UTF-8 locale either, and on some
systems, (for example iOS) I won't have any UTF-8 locale available for
std::locale constructor.
So I'm curious, why generator won't generate ctype locale? Is there any
reason behind it? Or maybe I'm doing something wrong? Is there any way to
generate locale with proper ctype facet from ICU using
boost::locale::generator?

-- 
--
With respect
Gleb "Crazy Sage" Igumnov                mailto:crazy.sage_at_[hidden]

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk