default_encoding_under_windows.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.6"/>
  7. <title>Boost.Locale: Default Encoding under Microsoft Windows</title>
  8. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  9. <script type="text/javascript" src="jquery.js"></script>
  10. <script type="text/javascript" src="dynsections.js"></script>
  11. <link href="navtree.css" rel="stylesheet" type="text/css"/>
  12. <script type="text/javascript" src="resize.js"></script>
  13. <script type="text/javascript" src="navtree.js"></script>
  14. <script type="text/javascript">
  15. $(document).ready(initResizable);
  16. $(window).load(resizeHeight);
  17. </script>
  18. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  19. </head>
  20. <body>
  21. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  22. <div id="titlearea">
  23. <table cellspacing="0" cellpadding="0">
  24. <tbody>
  25. <tr style="height: 56px;">
  26. <td id="projectlogo"><img alt="Logo" src="boost-small.png"/></td>
  27. <td style="padding-left: 0.5em;">
  28. <div id="projectname">Boost.Locale
  29. </div>
  30. </td>
  31. </tr>
  32. </tbody>
  33. </table>
  34. </div>
  35. <!-- end header part -->
  36. <!-- Generated by Doxygen 1.8.6 -->
  37. <div id="navrow1" class="tabs">
  38. <ul class="tablist">
  39. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  40. <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
  41. <li><a href="modules.html"><span>Modules</span></a></li>
  42. <li><a href="namespaces.html"><span>Namespaces</span></a></li>
  43. <li><a href="annotated.html"><span>Classes</span></a></li>
  44. <li><a href="files.html"><span>Files</span></a></li>
  45. <li><a href="examples.html"><span>Examples</span></a></li>
  46. </ul>
  47. </div>
  48. </div><!-- top -->
  49. <div id="side-nav" class="ui-resizable side-nav-resizable">
  50. <div id="nav-tree">
  51. <div id="nav-tree-contents">
  52. <div id="nav-sync" class="sync"></div>
  53. </div>
  54. </div>
  55. <div id="splitbar" style="-moz-user-select:none;"
  56. class="ui-resizable-handle">
  57. </div>
  58. </div>
  59. <script type="text/javascript">
  60. $(document).ready(function(){initNavTree('default_encoding_under_windows.html','');});
  61. </script>
  62. <div id="doc-content">
  63. <div class="header">
  64. <div class="headertitle">
  65. <div class="title">Default Encoding under Microsoft Windows </div> </div>
  66. </div><!--header-->
  67. <div class="contents">
  68. <div class="textblock"><p>All modern operating systems use Unicode.</p>
  69. <ul>
  70. <li>Unix operating system family use UTF-8 encoding by default.</li>
  71. <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>
  72. </ul>
  73. <p>As a result of radically different approaches, it is very hard to write portable Unicode aware applications.</p>
  74. <p>Boost Locale fully supports both narrow and wide API. The default character encoding is assumed to be UTF-8 on Windows.</p>
  75. <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>
  76. <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>
  77. <p>A good example of such library is Boost.Filesystem v3.</p>
  78. <p>For example</p>
  79. <div class="fragment"><div class="line"><span class="preprocessor">#include &lt;boost/locale.hpp&gt;</span></div>
  80. <div class="line"><span class="preprocessor">#include &lt;boost/filesystem/path.hpp&gt;</span></div>
  81. <div class="line"><span class="preprocessor">#include &lt;boost/filesystem/fstream.hpp&gt;</span></div>
  82. <div class="line"></div>
  83. <div class="line"><span class="keywordtype">int</span> main()</div>
  84. <div class="line">{</div>
  85. <div class="line"> <span class="comment">// Create and install global locale</span></div>
  86. <div class="line"> std::locale::global(<a class="code" href="classboost_1_1locale_1_1generator.html">boost::locale::generator</a>().generate(<span class="stringliteral">&quot;&quot;</span>));</div>
  87. <div class="line"> <span class="comment">// Make boost.filesystem use it</span></div>
  88. <div class="line"> boost::filesystem::path::imbue(std::locale());</div>
  89. <div class="line"> <span class="comment">// Now Works perfectly fine with UTF-8!</span></div>
  90. <div class="line"> boost::filesystem::ofstream hello(<span class="stringliteral">&quot;שלום.txt&quot;</span>); </div>
  91. <div class="line">}</div>
  92. </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>
  93. <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>
  94. <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>
  95. <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>
  96. </div></div><!-- contents -->
  97. </div><!-- doc-content -->
  98. <li class="footer">
  99. &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.
  100. </li>
  101. </ul>
  102. </div>
  103. </body>
  104. </html>