106 lines
5.7 KiB
HTML
106 lines
5.7 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"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
|
<meta name="generator" content="Doxygen 1.8.6"/>
|
|
<title>Boost.Locale: Default Encoding under Microsoft Windows</title>
|
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="jquery.js"></script>
|
|
<script type="text/javascript" src="dynsections.js"></script>
|
|
<link href="navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="resize.js"></script>
|
|
<script type="text/javascript" src="navtree.js"></script>
|
|
<script type="text/javascript">
|
|
$(document).ready(initResizable);
|
|
$(window).load(resizeHeight);
|
|
</script>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<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>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.8.6 -->
|
|
<div id="navrow1" class="tabs">
|
|
<ul class="tablist">
|
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
|
<li class="current"><a href="pages.html"><span>Related Pages</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><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
$(document).ready(function(){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"><div class="line"><span class="preprocessor">#include <boost/locale.hpp></span></div>
|
|
<div class="line"><span class="preprocessor">#include <boost/filesystem/path.hpp></span></div>
|
|
<div class="line"><span class="preprocessor">#include <boost/filesystem/fstream.hpp></span></div>
|
|
<div class="line"></div>
|
|
<div class="line"><span class="keywordtype">int</span> main()</div>
|
|
<div class="line">{</div>
|
|
<div class="line"> <span class="comment">// Create and install global locale</span></div>
|
|
<div class="line"> std::locale::global(<a class="code" href="classboost_1_1locale_1_1generator.html">boost::locale::generator</a>().generate(<span class="stringliteral">""</span>));</div>
|
|
<div class="line"> <span class="comment">// Make boost.filesystem use it</span></div>
|
|
<div class="line"> boost::filesystem::path::imbue(std::locale());</div>
|
|
<div class="line"> <span class="comment">// Now Works perfectly fine with UTF-8!</span></div>
|
|
<div class="line"> boost::filesystem::ofstream hello(<span class="stringliteral">"שלום.txt"</span>); </div>
|
|
<div class="line">}</div>
|
|
</div><!-- fragment --><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="section note"><dt>Note</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><!-- doc-content -->
|
|
|
|
<li class="footer">
|
|
© 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>
|