aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/utf8bidireorder_8cpp-source.html
blob: dc861ec02bb0ae4ad12d021e467e0d5e09c926d2 (plain) (tree)




































































                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>utf8bidireorder.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>utf8bidireorder.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment">*</font>
00003 <font class="comment">* utf8cnormalizer - SWFilter decendant to perform reordering of UTF-8</font>
00004 <font class="comment">*                   text to visual order according to Unicode BiDi</font>
00005 <font class="comment">*/</font>
00006 
00007 <font class="preprocessor">#ifdef _ICU_</font>
00008 <font class="preprocessor"></font>
00009 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00010 <font class="preprocessor">#include &lt;string.h&gt;</font>
00011 
00012 <font class="preprocessor">#ifdef __GNUC__</font>
00013 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unixstr.h&gt;</font>
00014 <font class="preprocessor">#endif</font>
00015 <font class="preprocessor"></font>
00016 <font class="preprocessor">#include &lt;utf8bidireorder.h&gt;</font>
00017 
00018 UTF8BiDiReorder::UTF8BiDiReorder() {
00019 
00020         conv = ucnv_open(<font class="stringliteral">"UTF-8"</font>, &amp;err);
00021 
00022 }
00023 
00024 UTF8BiDiReorder::~UTF8BiDiReorder() {
00025         ucnv_close(conv);
00026 }
00027 
00028 <font class="keywordtype">char</font> UTF8BiDiReorder::ProcessText(<font class="keywordtype">char</font> *text, <font class="keywordtype">int</font> maxlen, <font class="keyword">const</font> <a class="code" href="class_s_w_key.html">SWKey</a> *key, <font class="keyword">const</font> <a class="code" href="class_s_w_module.html">SWModule</a> *module)
00029 {
00030         UChar *ustr, *ustr2;
00031         
00032         int32_t len = strlen(text);
00033         ustr = <font class="keyword">new</font> UChar[len]; <font class="comment">//each char could become a surrogate pair</font>
00034 
00035         <font class="comment">// Convert UTF-8 string to UTF-16 (UChars)</font>
00036         len = ucnv_toUChars(conv, ustr, len, text, -1, &amp;err);
00037         ustr2 = <font class="keyword">new</font> UChar[len];
00038 
00039         UBiDi* bidi = ubidi_openSized(len + 1, 0, &amp;err);
00040         ubidi_setPara(bidi, ustr, len, UBIDI_DEFAULT_RTL, NULL, &amp;err);
00041         len = ubidi_writeReordered(bidi, ustr2, len,
00042                 UBIDI_DO_MIRRORING | UBIDI_REMOVE_BIDI_CONTROLS, &amp;err);
00043         ubidi_close(bidi);
00044 
00045 <font class="comment">//        len = ubidi_writeReverse(ustr, len, ustr2, len,</font>
00046 <font class="comment">//                UBIDI_DO_MIRRORING | UBIDI_REMOVE_BIDI_CONTROLS, &amp;err);</font>
00047 
00048         ucnv_fromUChars(conv, text, maxlen, ustr2, len, &amp;err);
00049 
00050         <font class="keyword">delete</font> [] ustr2;
00051         <font class="keyword">delete</font> [] ustr;
00052         <font class="keywordflow">return</font> 0;
00053 }
00054 
00055 <font class="preprocessor">#endif</font>
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:01 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>