locale/doc/html/classboost_1_1locale_1_1generic__codecvt.html
2015-10-18 17:31:48 +03:00

176 lines
13 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: boost::locale::generic_codecvt&lt; CharType, CodecvtImpl, CharSize &gt; Class Template Reference</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&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;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 class="current"><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 id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="annotated.html"><span>Class&#160;List</span></a></li>
<li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class&#160;Members</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('classboost_1_1locale_1_1generic__codecvt.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">boost::locale::generic_codecvt&lt; CharType, CodecvtImpl, CharSize &gt; Class Template Reference</div> </div>
</div><!--header-->
<div class="contents">
<p>Geneneric generic codecvt facet, various stateless encodings to UTF-16 and UTF-32 using wchar_t, char32_t and char16_t.
<a href="classboost_1_1locale_1_1generic__codecvt.html#details">More...</a></p>
<p><code>#include &lt;<a class="el" href="generic__codecvt_8hpp_source.html">boost/locale/generic_codecvt.hpp</a>&gt;</code></p>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template&lt;typename CharType, typename CodecvtImpl, int CharSize = sizeof(CharType)&gt;<br/>
class boost::locale::generic_codecvt&lt; CharType, CodecvtImpl, CharSize &gt;</h3>
<p>Geneneric generic codecvt facet, various stateless encodings to UTF-16 and UTF-32 using wchar_t, char32_t and char16_t. </p>
<p>Implementations should dervide from this class defining itself as CodecvtImpl and provide following members</p>
<ul>
<li><code>state_type</code> - a type of special object that allows to store intermediate cached data, for example <code>iconv_t</code> descriptor</li>
<li><code>state_type initial_state(generic_codecvt_base::initial_convertion_state direction) const</code> - member function that creates initial state</li>
<li><code>int max_encoding_length() const</code> - a maximal length that one Unicode code point is represented, for UTF-8 for example it is 4 from ISO-8859-1 it is 1</li>
<li><code><a class="el" href="namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8" title="The integral type that can hold a Unicode code point. ">utf::code_point</a> to_unicode(state_type &amp;state,char const *&amp;begin,char const *end)</code> - extract first code point from the text in range [begin,end), in case of success begin would point to the next character sequence to be encoded to next code point, in case of incomplete sequence - <a class="el" href="namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38" title="Special constant that defines incomplete code point. ">utf::incomplete</a> shell be returned, and in case of invalid input sequence <a class="el" href="namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb" title="Special constant that defines illegal code point. ">utf::illegal</a> shell be returned and begin would remain unmodified</li>
<li><code><a class="el" href="namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8" title="The integral type that can hold a Unicode code point. ">utf::code_point</a> from_unicode(state_type &amp;state,utf::code_point u,char *begin,char const *end)</code> - convert a unicode code point <code>u</code> into a character seqnece at [begin,end). Return the length of the sequence in case of success, <a class="el" href="namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38" title="Special constant that defines incomplete code point. ">utf::incomplete</a> in case of not enough room to encode the code point of <a class="el" href="namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb" title="Special constant that defines illegal code point. ">utf::illegal</a> in case conversion can not be performed</li>
</ul>
<p>For example implementaion of codecvt for latin1/ISO-8859-1 character set</p>
<div class="fragment"><div class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> CharType&gt;</div>
<div class="line"><span class="keyword">class </span>latin1_codecvt :<a class="code" href="classboost_1_1locale_1_1generic__codecvt.html">boost::locale::generic_codecvt</a>&lt;CharType,latin1_codecvt&lt;CharType&gt; &gt; </div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* Standard codecvt constructor */</span> </div>
<div class="line"> latin1_codecvt(<span class="keywordtype">size_t</span> refs = 0) : boost::locale::generic_codecvt&lt;CharType,latin1_codecvt&lt;CharType&gt; &gt;(refs) </div>
<div class="line"> {</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* State is unused but required by generic_codecvt */</span></div>
<div class="line"> <span class="keyword">struct </span>state_type {};</div>
<div class="line"></div>
<div class="line"> state_type initial_state(<a class="code" href="classboost_1_1locale_1_1generic__codecvt__base.html#af28c4b64af6cbf2eb01c444e2cdf08c3">generic_codecvt_base::initial_convertion_state</a> <span class="comment">/*unused*/</span>)<span class="keyword"> const</span></div>
<div class="line"><span class="keyword"> </span>{</div>
<div class="line"> <span class="keywordflow">return</span> state_type();</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="keywordtype">int</span> max_encoding_length()<span class="keyword"> const</span></div>
<div class="line"><span class="keyword"> </span>{</div>
<div class="line"> <span class="keywordflow">return</span> 1;</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <a class="code" href="namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8">boost::locale::utf::code_point</a> to_unicode(state_type &amp;,<span class="keywordtype">char</span> <span class="keyword">const</span> *&amp;begin,<span class="keywordtype">char</span> <span class="keyword">const</span> *end)<span class="keyword"> const</span></div>
<div class="line"><span class="keyword"> </span>{</div>
<div class="line"> <span class="keywordflow">if</span>(begin == end)</div>
<div class="line"> <span class="keywordflow">return</span> <a class="code" href="namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38">boost::locale::utf::incomplete</a>;</div>
<div class="line"> <span class="keywordflow">return</span> *begin++; </div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <a class="code" href="namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8">boost::locale::utf::code_point</a> from_unicode(state_type &amp;,<a class="code" href="namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8">boost::locale::utf::code_point</a> u,<span class="keywordtype">char</span> *begin,<span class="keywordtype">char</span> <span class="keyword">const</span> *end)<span class="keyword"> const</span></div>
<div class="line"><span class="keyword"> </span>{</div>
<div class="line"> <span class="keywordflow">if</span>(u &gt;= 256)</div>
<div class="line"> <span class="keywordflow">return</span> <a class="code" href="namespaceboost_1_1locale_1_1utf.html#a30010000878c7732340bda8956b844fb">boost::locale::utf::illegal</a>;</div>
<div class="line"> <span class="keywordflow">if</span>(begin == end)</div>
<div class="line"> <span class="keywordflow">return</span> <a class="code" href="namespaceboost_1_1locale_1_1utf.html#a20dbe458fd18229a0e6c09888d031b38">boost::locale::utf::incomplete</a>;</div>
<div class="line"> *begin = u;</div>
<div class="line"> <span class="keywordflow">return</span> 1; </div>
<div class="line"> }</div>
<div class="line">};</div>
</div><!-- fragment --><p>When external tools used for encoding conversion, the <code>state_type</code> is useful to save objects used for conversions. For example, icu::UConverter can be saved in such a state for an efficient use:</p>
<div class="fragment"><div class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> CharType&gt;</div>
<div class="line"><span class="keyword">class </span>icu_codecvt :<a class="code" href="classboost_1_1locale_1_1generic__codecvt.html">boost::locale::generic_codecvt</a>&lt;CharType,icu_codecvt&lt;CharType&gt; &gt; </div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> </div>
<div class="line"> <span class="comment">/* Standard codecvt constructor */</span> </div>
<div class="line"> icu_codecvt(std::string <span class="keyword">const</span> &amp;name,refs = 0) : </div>
<div class="line"> boost::locale::generic_codecvt&lt;CharType,latin1_codecvt&lt;CharType&gt; &gt;(refs)</div>
<div class="line"> { ... }</div>
<div class="line"></div>
<div class="line"> <span class="comment">/* State is unused but required by generic_codecvt */</span></div>
<div class="line"> <span class="keyword">struct </span>std::unique_ptr&lt;UConverter,void (*)(UConverter*)&gt; state_type;</div>
<div class="line"></div>
<div class="line"> state_type &amp;&amp;initial_state(<a class="code" href="classboost_1_1locale_1_1generic__codecvt__base.html#af28c4b64af6cbf2eb01c444e2cdf08c3">generic_codecvt_base::initial_convertion_state</a> <span class="comment">/*unused*/</span>)<span class="keyword"> const</span></div>
<div class="line"><span class="keyword"> </span>{</div>
<div class="line"> UErrorCode err = U_ZERO_ERROR;</div>
<div class="line"> state_type ptr(ucnv_safeClone(converter_,0,0,&amp;err,ucnv_close);</div>
<div class="line"> <span class="keywordflow">return</span> std::move(ptr);</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8">boost::locale::utf::code_point</a> to_unicode(state_type &amp;ptr,<span class="keywordtype">char</span> <span class="keyword">const</span> *&amp;begin,<span class="keywordtype">char</span> <span class="keyword">const</span> *end)<span class="keyword"> const</span></div>
<div class="line"><span class="keyword"> </span>{</div>
<div class="line"> UErrorCode err = U_ZERO_ERROR;</div>
<div class="line"> <a class="code" href="namespaceboost_1_1locale_1_1utf.html#a068111a6b9d6d465a63893ed5c05e2f8">boost::locale::utf::code_point</a> cp = ucnv_getNextUChar(ptr.get(),&amp;begin,end,&amp;err);</div>
<div class="line"> ...</div>
<div class="line"> }</div>
<div class="line"> ...</div>
<div class="line">};</div>
</div><!-- fragment --> </div><hr/>The documentation for this class was generated from the following file:<ul>
<li>boost/locale/<a class="el" href="generic__codecvt_8hpp_source.html">generic_codecvt.hpp</a></li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<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>