<!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>ucommon: unicode.cpp</title> <link href="tabs.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="navtree.js"></script> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript"> $(document).ready(initResizable); </script> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.7.3 --> <div id="top"> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">ucommon</div> </td> </tr> </tbody> </table> </div> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Data Structures</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> <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('a00011.html',''); </script> <div id="doc-content"> <div class="header"> <div class="headertitle"> <h1>unicode.cpp</h1> </div> </div> <div class="contents"> <p>An example of some unicode-utf8 transcoding.</p> <div class="fragment"><pre class="fragment"><span class="comment">// Copyright (C) 2009-2010 David Sugar, Tycho Softworks.</span> <span class="comment">//</span> <span class="comment">// This file is part of GNU uCommon C++.</span> <span class="comment">//</span> <span class="comment">// GNU uCommon C++ is free software: you can redistribute it and/or modify</span> <span class="comment">// it under the terms of the GNU Lesser General Public License as published</span> <span class="comment">// by the Free Software Foundation, either version 3 of the License, or</span> <span class="comment">// (at your option) any later version.</span> <span class="comment">//</span> <span class="comment">// GNU uCommon C++ is distributed in the hope that it will be useful,</span> <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span> <span class="comment">// GNU Lesser General Public License for more details.</span> <span class="comment">//</span> <span class="comment">// You should have received a copy of the GNU Lesser General Public License</span> <span class="comment">// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.</span> <span class="preprocessor">#ifndef DEBUG</span> <span class="preprocessor"></span><span class="preprocessor">#define DEBUG</span> <span class="preprocessor"></span><span class="preprocessor">#endif</span> <span class="preprocessor"></span> <span class="preprocessor">#include <<a class="code" href="a00202.html" title="Top level include file for the GNU uCommon C++ core library.">ucommon/ucommon.h</a>></span> <span class="preprocessor">#include <stdio.h></span> <span class="keyword">using namespace </span>UCOMMON_NAMESPACE; <span class="keyword">extern</span> <span class="stringliteral">"C"</span> <span class="keywordtype">int</span> main() { <span class="keywordtype">char</span> u1[] = {(char)0xc2, (<span class="keywordtype">char</span>)0xa9, 0x00}; <span class="keywordtype">char</span> u2[] = {(char)0xe2, (<span class="keywordtype">char</span>)0x89, (char)0xa0, 0x00}; assert(<a name="a0"></a><a class="code" href="a00169.html#ae4c4b68b3800bcae0dbf1e20925597c7" title="Compute character size of utf8 string codepoint.">utf8::size</a>(u1) == 2); assert(<a class="code" href="a00169.html#ae4c4b68b3800bcae0dbf1e20925597c7" title="Compute character size of utf8 string codepoint.">utf8::size</a>(u2) == 3); assert(<a name="a1"></a><a class="code" href="a00169.html#a47b2778d64cf8dde592b5f6723bcde95" title="Count ut8 encoded ucs4 codepoints in string.">utf8::count</a>(u1) == 1); assert(<a class="code" href="a00169.html#a47b2778d64cf8dde592b5f6723bcde95" title="Count ut8 encoded ucs4 codepoints in string.">utf8::count</a>(u2) == 1); assert(<a name="a2"></a><a class="code" href="a00169.html#ab3ce5bb81e28667b35049d2a7d21f47b" title="Convert a utf8 encoded codepoint to a ucs4 character value.">utf8::codepoint</a>(u1) == 0x00a9); assert(<a class="code" href="a00169.html#ab3ce5bb81e28667b35049d2a7d21f47b" title="Convert a utf8 encoded codepoint to a ucs4 character value.">utf8::codepoint</a>(u2) == 0x2260); } </pre></div> </div> </div> </div> <div id="nav-path" class="navpath"> <ul> <li class="footer">Generated on Wed Apr 13 2011 22:39:47 for ucommon by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.3 </li> </ul> </div> </body> </html>