2
0
mirror of https://github.com/boostorg/locale.git synced 2026-01-26 06:32:24 +00:00
Files
locale/doc/html/encoding__utf_8hpp_source.html
Artyom Beilis d5c19fcc19 Updated documentation
[SVN r73646]
2011-08-11 10:11:54 +00:00

156 lines
12 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: boost/locale/encoding_utf.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
<!--
Switch the lines for stand alone version
<link rel="stylesheet" type="text/css" href="http://www.boost.org/style-v2/section-basic.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/">
<!--
Switch the lines for stand alone version
<img src="http://www.boost.org/gfx/space.png" alt= "Boost C++ Libraries" class="heading-logo" />
-->
<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 class="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
<div class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&nbsp;List</span></a></li>
</ul>
</div>
<div class="header">
<div class="headertitle">
<h1>boost/locale/encoding_utf.hpp</h1> </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//</span>
<a name="l00002"></a>00002 <span class="comment">// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)</span>
<a name="l00003"></a>00003 <span class="comment">//</span>
<a name="l00004"></a>00004 <span class="comment">// Distributed under the Boost Software License, Version 1.0. (See</span>
<a name="l00005"></a>00005 <span class="comment">// accompanying file LICENSE_1_0.txt or copy at</span>
<a name="l00006"></a>00006 <span class="comment">// http://www.boost.org/LICENSE_1_0.txt)</span>
<a name="l00007"></a>00007 <span class="comment">//</span>
<a name="l00008"></a>00008 <span class="preprocessor">#ifndef BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#define BOOST_LOCALE_ENCODING_UTF_HPP_INCLUDED</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;boost/locale/utf.hpp&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;boost/locale/encoding_errors.hpp&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;iterator&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#ifdef BOOST_MSVC</span>
<a name="l00015"></a>00015 <span class="preprocessor"></span><span class="preprocessor"># pragma warning(push)</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor"># pragma warning(disable : 4275 4251 4231 4660)</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span>
<a name="l00019"></a>00019
<a name="l00020"></a>00020
<a name="l00021"></a>00021 <span class="keyword">namespace </span>boost {
<a name="l00022"></a>00022 <span class="keyword">namespace </span>locale {
<a name="l00023"></a>00023 <span class="keyword">namespace </span>conv {
<a name="l00028"></a>00028
<a name="l00032"></a>00032 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> CharOut,<span class="keyword">typename</span> CharIn&gt;
<a name="l00033"></a>00033 std::basic_string&lt;CharOut&gt;
<a name="l00034"></a><a class="code" href="group__codepage.html#ga2de4d9d38004e5d7146abf2bd6a3df0b">00034</a> <a class="code" href="group__codepage.html#ga2de4d9d38004e5d7146abf2bd6a3df0b">utf_to_utf</a>(CharIn <span class="keyword">const</span> *begin,CharIn <span class="keyword">const</span> *end,<a class="code" href="group__codepage.html#ga8e3c5a274f57107ec5745e227c26ba84">method_type</a> how = <a class="code" href="group__codepage.html#gga8e3c5a274f57107ec5745e227c26ba84adcdc34a57dd2a3ca917f73c13f18b559" title="Default method - skip.">default_method</a>)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036 std::basic_string&lt;CharOut&gt; result;
<a name="l00037"></a>00037 result.reserve(end-begin);
<a name="l00038"></a>00038 <span class="keyword">typedef</span> std::back_insert_iterator&lt;std::basic_string&lt;CharOut&gt; &gt; inserter_type;
<a name="l00039"></a>00039 inserter_type inserter(result);
<a name="l00040"></a>00040 <a class="code" href="namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8" title="The integral type type that can hold a Unicode code point.">utf::code_point</a> c;
<a name="l00041"></a>00041 <span class="keywordflow">while</span>(begin!=end) {
<a name="l00042"></a>00042 c=<a class="code" href="structboost_1_1locale_1_1utf_1_1utf__traits.html" title="UTF Traits class - functions to convert UTF sequences to and from Unicode code points.">utf::utf_traits&lt;CharIn&gt;::template</a> decode&lt;CharIn const *&gt;(begin,end);
<a name="l00043"></a>00043 <span class="keywordflow">if</span>(c==<a class="code" href="namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb" title="Special constant that defines illegal code point.">utf::illegal</a> || c==<a class="code" href="namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38" title="Special constant that defines incomplete code point.">utf::incomplete</a>) {
<a name="l00044"></a>00044 <span class="keywordflow">if</span>(how==<a class="code" href="group__codepage.html#gga8e3c5a274f57107ec5745e227c26ba84aab08f9ee241c405ef40bd3cedb43b383" title="Stop conversion and throw conversion_error.">stop</a>)
<a name="l00045"></a>00045 <span class="keywordflow">throw</span> <a class="code" href="classboost_1_1locale_1_1conv_1_1conversion__error.html" title="The excepton that is thrown in case of conversion error.">conversion_error</a>();
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 <span class="keywordflow">else</span> {
<a name="l00048"></a>00048 <a class="code" href="structboost_1_1locale_1_1utf_1_1utf__traits.html" title="UTF Traits class - functions to convert UTF sequences to and from Unicode code points.">utf::utf_traits&lt;CharOut&gt;::template</a> encode&lt;inserter_type&gt;(c,inserter);
<a name="l00049"></a>00049 }
<a name="l00050"></a>00050 }
<a name="l00051"></a>00051 <span class="keywordflow">return</span> result;
<a name="l00052"></a>00052 }
<a name="l00053"></a>00053
<a name="l00057"></a>00057 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> CharOut,<span class="keyword">typename</span> CharIn&gt;
<a name="l00058"></a>00058 std::basic_string&lt;CharOut&gt;
<a name="l00059"></a><a class="code" href="group__codepage.html#gae36d1fa29f675c4f13164afd8e0fabde">00059</a> <a class="code" href="group__codepage.html#ga2de4d9d38004e5d7146abf2bd6a3df0b">utf_to_utf</a>(CharIn <span class="keyword">const</span> *str,<a class="code" href="group__codepage.html#ga8e3c5a274f57107ec5745e227c26ba84">method_type</a> how = <a class="code" href="group__codepage.html#gga8e3c5a274f57107ec5745e227c26ba84adcdc34a57dd2a3ca917f73c13f18b559" title="Default method - skip.">default_method</a>)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061 CharIn <span class="keyword">const</span> *end = str;
<a name="l00062"></a>00062 <span class="keywordflow">while</span>(*end)
<a name="l00063"></a>00063 end++;
<a name="l00064"></a>00064 <span class="keywordflow">return</span> utf_to_utf&lt;CharOut,CharIn&gt;(str,end,how);
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066
<a name="l00067"></a>00067
<a name="l00071"></a>00071 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> CharOut,<span class="keyword">typename</span> CharIn&gt;
<a name="l00072"></a>00072 std::basic_string&lt;CharOut&gt;
<a name="l00073"></a><a class="code" href="group__codepage.html#ga2aa7d34682ff4e66b297ab5d75e1de51">00073</a> <a class="code" href="group__codepage.html#ga2de4d9d38004e5d7146abf2bd6a3df0b">utf_to_utf</a>(std::basic_string&lt;CharIn&gt; <span class="keyword">const</span> &amp;str,<a class="code" href="group__codepage.html#ga8e3c5a274f57107ec5745e227c26ba84">method_type</a> how = <a class="code" href="group__codepage.html#gga8e3c5a274f57107ec5745e227c26ba84adcdc34a57dd2a3ca917f73c13f18b559" title="Default method - skip.">default_method</a>)
<a name="l00074"></a>00074 {
<a name="l00075"></a>00075 <span class="keywordflow">return</span> utf_to_utf&lt;CharOut,CharIn&gt;(str.c_str(),str.c_str()+str.size(),how);
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077
<a name="l00078"></a>00078
<a name="l00080"></a>00080
<a name="l00081"></a>00081 } <span class="comment">// conv</span>
<a name="l00082"></a>00082
<a name="l00083"></a>00083 } <span class="comment">// locale</span>
<a name="l00084"></a>00084 } <span class="comment">// boost</span>
<a name="l00085"></a>00085
<a name="l00086"></a>00086 <span class="preprocessor">#ifdef BOOST_MSVC</span>
<a name="l00087"></a>00087 <span class="preprocessor"></span><span class="preprocessor">#pragma warning(pop)</span>
<a name="l00088"></a>00088 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00089"></a>00089 <span class="preprocessor"></span>
<a name="l00090"></a>00090 <span class="preprocessor">#endif</span>
<a name="l00091"></a>00091 <span class="preprocessor"></span>
<a name="l00092"></a>00092 <span class="comment">// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4</span>
<a name="l00093"></a>00093
</pre></div></div>
</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>