PrevUpHomeNext

Locale Support

Locale support is similar to the formatting support as demonstrated by the following example:

namespace cnv = boost::cnv;
namespace arg = boost::cnv::parameter;

    boost::cnv::cstream cnv;
    std::locale  rus_locale;
    std::locale  eng_locale;

    char const* eng_locale_name = test::cnv::is_msc ? "English_United States.1251" : "en_US.UTF-8";
    char const* rus_locale_name = test::cnv::is_msc ? "Russian_Russia.1251" : "ru_RU.UTF-8";
    char const*    rus_expected = test::cnv::is_msc ? "1,235e-002"  : "1,235e-02";
    char const*    eng_expected = test::cnv::is_msc ? "1.235e-002"  : "1.235e-02";
    char const*    dbl_expected = test::cnv::is_msc ? "1.2345E-002" : "1.2345E-02";

//  cnv(std::setprecision(4))(std::uppercase)(std::scientific);
    cnv(arg::precision = 4)
       (arg::uppercase = true)
       (arg::notation = cnv::notation::scientific);

    double double_v01 = convert<double>(dbl_expected, cnv).value_or(0);
    string double_s02 = convert<string>(double_v01, cnv).value_or("bad");

    BOOST_TEST(dbl_expected == double_s02);

    try { rus_locale = std::locale(rus_locale_name); }
    catch (...) { printf("Bad locale %s.\n", rus_locale_name); exit(1); }

    try { eng_locale = std::locale(eng_locale_name); }
    catch (...) { printf("Bad locale %s.\n", eng_locale_name); exit(1); }

//  cnv(std::setprecision(3))(std::nouppercase);
    cnv(arg::precision = 3)(arg::uppercase = false);

    string double_rus = convert<string>(double_v01, cnv(rus_locale)).value_or("bad double_rus");
    string double_eng = convert<string>(double_v01, cnv(eng_locale)).value_or("bad double_eng");

    BOOST_TEST(double_rus == rus_expected);
    BOOST_TEST(double_eng == eng_expected);


PrevUpHomeNext