blob: 8bb27ae4aa1ee989661008d7027e89c5e991c442 [file] [log] [blame]
<!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"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<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 href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
</head>
<body>
<div id="top"><!-- do not remove this div! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="boost-small.png"/></td>
<td style="padding-left: 0.5em;">
<div id="projectname">Boost.Locale
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.7.6.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;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>
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
initNavTree('default_encoding_under_windows.html','');
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">Default Encoding under Microsoft Windows </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><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></div><!-- contents -->
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">Boost.Locale</a> </li>
<li class="navelem"><a class="el" href="appendix.html">Appendix</a> </li>
<li class="footer">
&copy; Copyright 2009-2012 Artyom Beilis, Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>, Version 1.0.
</li>
</ul>
</div>
</body>
</html>