Boost C++ Libraries: Ticket #8570: boost::locale::generator::use_ansi_encoding bug: gives the unexpected result on Win7 Chinese. https://svn.boost.org/trac10/ticket/8570 <p> boost::locale::generator gen; gen.use_ansi_encoding(true); strLocaleName = std::use_facet&lt;boost::locale::info&gt;( gen("")).name(); gen.use_ansi_encoding(false); strLocaleName = std::use_facet&lt;boost::locale::info&gt;( gen("")).name(); </p> <p> 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. </p> <p> And why get_system_locale give the expected result ? get_system_locale(true); <em> "zh_CN.UTF-8" get_system_locale(false); </em> "zh_CN.windows-936" </p> <p> 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, </p> <blockquote> <p> std::use_facet&lt;boost::locale::info&gt;(gen(strCodePage)).encoding()); </p> </blockquote> <p> Is this a bug of boost::locale::generator::use_ansi_encoding ? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8570 Trac 1.4.3 anonymous Tue, 14 May 2013 01:34:31 GMT <link>https://svn.boost.org/trac10/ticket/8570#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8570#comment:1</guid> <description> <p> Sorry, the format is chaos. Follow is the right format: </p> <p> void f() </p> <p> { </p> <p> boost::locale::generator gen; </p> <p> std::string strLocaleName; </p> <p> gen.use_ansi_encoding(true); </p> <p> strLocaleName = std::use_facet&lt;boost::locale::info&gt;( gen("")).name(); </p> <p> gen.use_ansi_encoding(false); </p> <p> strLocaleName = std::use_facet&lt;boost::locale::info&gt;( gen("")).name(); </p> <p> } </p> <p> strLocaleName always "zh_CN.UTF-8", </p> <p> why i can't get "zh_CN.GB2312" ? </p> <p> I want to convert wstring to string. </p> <p> But </p> <p> string = boost::locale::conv::from_utf(wstring, gen("")); </p> <p> is same with </p> <p> string = boost::locale::conv::from_utf(wstring, gen("UTF-8")); </p> <p> so it gives the unexpected result. </p> <p> And why get_system_locale give the expected result ? </p> <p> get_system_locale(true); <em> "zh_CN.UTF-8" </em></p> <p> get_system_locale(false); <em> "zh_CN.windows-936" </em></p> <p> So I have to use this code, </p> <p> boost::locale::generator gen; </p> <p> strCodePage = boost::locale::util::get_system_locale(); </p> <p> string = boost::locale::conv::from_utf( wstring, </p> <blockquote> <p> std::use_facet&lt;boost::locale::info&gt;(gen(strCodePage)).encoding()); </p> </blockquote> <p> Is this a bug of boost::locale::generator::use_ansi_encoding ? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Artyom Beilis</dc:creator> <pubDate>Tue, 14 May 2013 07:07:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8570#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8570#comment:2</guid> <description> <p> What backends are compiled in? Does ICU compiled in? Does std backend compiled in? What compiler? </p> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 14 May 2013 13:06:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8570#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8570#comment:3</guid> <description> <p> Thanks, I was complied in VS2010,and not use ICU. But follow ways not to specify std backend explicitly. Only to use locale(""); </p> <p> 1. </p> <pre class="wiki">setlocale(LC_CTYPE,""); wcstombs(string, wstring, _MAX_FNAME); </pre><p> 2. </p> <pre class="wiki">std::locale sys_locale(""); std::use_facet&lt;std::codecvt&lt;wchar_t,char, mbstate_t&gt; &gt;(sys_locale).out(...); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 14 May 2013 13:09:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8570#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8570#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/8570#comment:2" title="Comment 2">artyom</a>: </p> <blockquote class="citation"> <p> What backends are compiled in? Does ICU compiled in? Does std backend compiled in? What compiler? </p> <p> 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. </p> </blockquote> <p> Thanks, I was complied in VS2010,and not use ICU. But follow ways not to specify std backend explicitly. Only to use locale(""); </p> <p> 1. </p> <pre class="wiki">setlocale(LC_CTYPE,""); wcstombs(string, wstring, _MAX_FNAME); </pre><p> 2. </p> <pre class="wiki">std::locale sys_locale(""); std::use_facet&lt;std::codecvt&lt;wchar_t,char, mbstate_t&gt; &gt;(sys_locale).out(...); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Artyom Beilis</dc:creator> <pubDate>Thu, 13 Jul 2017 14:14:31 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8570#comment:5 https://svn.boost.org/trac10/ticket/8570#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> Ticket