Opened 9 years ago
Closed 5 years ago
#8570 closed Bugs (invalid)
boost::locale::generator::use_ansi_encoding bug: gives the unexpected result on Win7 Chinese.
Reported by: | Owned by: | Artyom Beilis | |
---|---|---|---|
Milestone: | To Be Determined | Component: | locale |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | Cc: |
Description
boost::locale::generator gen; gen.use_ansi_encoding(true); strLocaleName = std::use_facet<boost::locale::info>( gen("")).name(); gen.use_ansi_encoding(false); strLocaleName = std::use_facet<boost::locale::info>( gen("")).name();
strLocaleName always "zh_CN.UTF-8", why i can't get "zh_CN.GB2312" ? I want to convert wstring to string.Milestone But string = boost::locale::conv::from_utf(wstring, gen("")); is same with string = boost::locale::conv::from_utf(wstring, gen("UTF-8")); so it gives the unexpected result.
And why get_system_locale give the expected result ? get_system_locale(true); "zh_CN.UTF-8" get_system_locale(false); "zh_CN.windows-936"
So I have to use this code, boost::locale::generator gen; strCodePage = boost::locale::util::get_system_locale(); string = boost::locale::conv::from_utf( wstring,
std::use_facet<boost::locale::info>(gen(strCodePage)).encoding());
Is this a bug of boost::locale::generator::use_ansi_encoding ?
Change History (5)
comment:1 by , 9 years ago
follow-up: 4 comment:2 by , 9 years ago
What backends are compiled in? Does ICU compiled in? Does std backend compiled in? What compiler?
Note: winapi backend (which is default on windows if ICU is not present) does not support ANSI encoding. So you need to specify std backend explicitly or use ICU.
comment:3 by , 9 years ago
Thanks, I was complied in VS2010,and not use ICU. But follow ways not to specify std backend explicitly. Only to use locale("");
1.
setlocale(LC_CTYPE,""); wcstombs(string, wstring, _MAX_FNAME);
2.
std::locale sys_locale(""); std::use_facet<std::codecvt<wchar_t,char, mbstate_t> >(sys_locale).out(...);
comment:4 by , 9 years ago
Replying to artyom:
What backends are compiled in? Does ICU compiled in? Does std backend compiled in? What compiler?
Note: winapi backend (which is default on windows if ICU is not present) does not support ANSI encoding. So you need to specify std backend explicitly or use ICU.
Thanks, I was complied in VS2010,and not use ICU. But follow ways not to specify std backend explicitly. Only to use locale("");
1.
setlocale(LC_CTYPE,""); wcstombs(string, wstring, _MAX_FNAME);
2.
std::locale sys_locale(""); std::use_facet<std::codecvt<wchar_t,char, mbstate_t> >(sys_locale).out(...);
comment:5 by , 5 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Sorry, the format is chaos. Follow is the right format:
void f()
{
boost::locale::generator gen;
std::string strLocaleName;
gen.use_ansi_encoding(true);
strLocaleName = std::use_facet<boost::locale::info>( gen("")).name();
gen.use_ansi_encoding(false);
strLocaleName = std::use_facet<boost::locale::info>( gen("")).name();
}
strLocaleName always "zh_CN.UTF-8",
why i can't get "zh_CN.GB2312" ?
I want to convert wstring to string.
But
string = boost::locale::conv::from_utf(wstring, gen(""));
is same with
string = boost::locale::conv::from_utf(wstring, gen("UTF-8"));
so it gives the unexpected result.
And why get_system_locale give the expected result ?
get_system_locale(true); "zh_CN.UTF-8"
get_system_locale(false); "zh_CN.windows-936"
So I have to use this code,
boost::locale::generator gen;
strCodePage = boost::locale::util::get_system_locale();
string = boost::locale::conv::from_utf( wstring,
Is this a bug of boost::locale::generator::use_ansi_encoding ?