blob: 8729f82a1fd5bda53c42ec7710c88a2a93430552 [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: 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" />
<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 class="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&#160;List</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('encoding__utf_8hpp.html','');
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">boost/locale/encoding_utf.hpp</div> </div>
</div><!--header-->
<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#gaf0ad39959911b000706e0538ec059d44">00034</a> <a class="code" href="group__codepage.html#gaf0ad39959911b000706e0538ec059d44">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 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#gaa4de44e37cbe5ec4a4b79e1d9bbaf4a7">00059</a> <a class="code" href="group__codepage.html#gaf0ad39959911b000706e0538ec059d44">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#ga1951228e7f528a20e40258d73cf17f5c">00073</a> <a class="code" href="group__codepage.html#gaf0ad39959911b000706e0538ec059d44">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><!-- contents -->
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><b>encoding_utf.hpp</b> </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>