2
0
mirror of https://github.com/boostorg/locale.git synced 2026-02-22 15:32:26 +00:00
Files
locale/doc/html/default_encoding_under_windows.html
Artyom Beilis 48ff4519b8 - Updates according to library requirements
- cleanup of inspect warnings
  - various requiremets like libraries.htm and maintainers.txt


[SVN r73786]
2011-08-15 19:04:34 +00:00

98 lines
5.3 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Boost.Locale: Default Encoding under Microsoft Windows</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="../style/section-basic.css">
</head>
<body>
<div id="boost-common-heading-doc">
<div class="heading-inner">
<div class="heading-placard"></div>
<h1 class="heading-title">
<a href="http://www.boost.org/">
<img src="../style/space.png" alt= "Boost C++ Libraries" class="heading-logo" />
<span class="heading-boost">Boost</span>
<span class="heading-cpplibraries">C++ Libraries</span>
</a>
</h1>
<p class="heading-quote">
<q>...one of the most highly
regarded and expertly designed C++ library projects in the
world.</q>
<span class="heading-attribution">&mdash; <a href=
"http://www.gotw.ca/" class="external">Herb Sutter</a> and <a href=
"http://en.wikipedia.org/wiki/Andrei_Alexandrescu" class="external">Andrei
Alexandrescu</a>, <a href=
"http://safari.awprofessional.com/?XmlId=0321113586" class="external">C++
Coding Standards</a></span>
</p>
</div>
</div>
<div id="boost-common-heading-doc-spacer"></div>
<!-- Generated by Doxygen 1.7.1 -->
<div class="navigation" id="top">
<div class="tabs">
<ul class="tablist">
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
<div class="navpath">
<ul>
<li><a class="el" href="main.html">Boost.Locale</a> </li>
<li><a class="el" href="appendix.html">Appendix</a> </li>
</ul>
</div>
</div>
<div class="header">
<div class="headertitle">
<h1>Default Encoding under Microsoft Windows </h1> </div>
</div>
<div class="contents">
<p>All modern operating systems use Unicode.</p>
<ul>
<li>Unix operating system family use UTF-8 encoding by default.</li>
<li>Microsoft Windows had migrated to Wide/UTF-16 API. The narrow encodings had been deprecated and the native OS API became so called "Wide API"</li>
</ul>
<p>As a result of radically different approaches, it is very hard to write portable Unicode aware applications.</p>
<p>Boost Locale fully supports both narrow and wide API. The default character encoding is assumed to be UTF-8 on Windows.</p>
<p>So if the default operating system Locale is "English_USA.1252" the default locale for Boost.Locale on Windows would be "en_US.UTF-8".</p>
<p>When the created locale object is installed globally then any libraries that use <code>std::codecvt</code> for conversion between narrow API and the native wide API would handle UTF-8 correctly.</p>
<p>A good example of such library is Boost.Filesystem v3.</p>
<p>For example</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;boost/locale.hpp&gt;</span>
<span class="preprocessor">#include &lt;boost/filesystem/path.hpp&gt;</span>
<span class="preprocessor">#include &lt;boost/filesystem/fstream.hpp&gt;</span>
<span class="keywordtype">int</span> main()
{
<span class="comment">// Create and install global locale</span>
std::locale::global(<a class="code" href="classboost_1_1locale_1_1generator.html" title="the major class used for locale generation">boost::locale::generator</a>().generate(<span class="stringliteral">&quot;&quot;</span>));
<span class="comment">// Make boost.filesystem use it</span>
boost::filesystem::path::imbue(std::locale());
<span class="comment">// Now Works perfectly fine with UTF-8!</span>
boost::filesystem::ofstream hello(<span class="stringliteral">&quot;שלום.txt&quot;</span>);
}
</pre></div><p>However such behavior may break existing software that assumes that the current encoding is single byte encodings like code page 1252.</p>
<p><a class="el" href="classboost_1_1locale_1_1generator.html">boost::locale::generator</a> class has a property <a class="el" href="classboost_1_1locale_1_1generator.html#a9afb2b0791abbabd39c800e08d9c9717">use_ansi_encoding()</a> that allows to change the behavior to legacy one and select an ANSI code page as default system encoding.</p>
<p>So, when the current locale is "English_USA.1252" and the <code>use_ansi_encoding</code> is turned on then the default locale would be "en_US.windows-1252"</p>
<dl class="note"><dt><b>Note:</b></dt><dd><code>winapi</code> backend does not support ANSI encodings, thus UTF-8 encoding is always used for narrow characters. </dd></dl>
</div>
<hr class="footer"/><address class="footer"><small>
&copy; Copyright 2009-2011 Artyom Beilis, Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>, Version 1.0.
</small></address>
</body>
</html>