<!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>utf8utf16.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> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center> <hr><h1>utf8utf16.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font> 00002 <font class="comment"> *</font> 00003 <font class="comment"> * UTF8UTF16 - SWFilter decendant to convert UTF-8 to UTF-16</font> 00004 <font class="comment"> *</font> 00005 <font class="comment"> */</font> 00006 00007 <font class="preprocessor">#include <stdlib.h></font> 00008 <font class="preprocessor">#include <stdio.h></font> 00009 00010 <font class="preprocessor">#include <utf8utf16.h></font> 00011 00012 UTF8UTF16::UTF8UTF16() { 00013 } 00014 00015 00016 <font class="keywordtype">char</font> UTF8UTF16::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) 00017 { 00018 <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> *from; 00019 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> *to; 00020 00021 <font class="keywordtype">int</font> len; 00022 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> uchar; 00023 <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> significantFirstBits, subsequent; 00024 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> schar; 00025 00026 len = strlen(text) + 1; <font class="comment">// shift string to right of buffer</font> 00027 <font class="keywordflow">if</font> (len < maxlen) { 00028 memmove(&text[maxlen - len], text, len); 00029 from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)&text[maxlen - len]; 00030 } 00031 <font class="keywordflow">else</font> 00032 from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)text; 00033 00034 00035 <font class="comment">// -------------------------------</font> 00036 00037 <font class="keywordflow">for</font> (to = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>*)text; *from; from++) { 00038 uchar = 0; 00039 <font class="keywordflow">if</font> ((*from & 128) != 128) { 00040 <font class="comment">// if (*from != ' ')</font> 00041 uchar = *from; 00042 } 00043 <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((*from & 128) && ((*from & 64) != 64)) { 00044 <font class="comment">// error, do nothing</font> 00045 <font class="keywordflow">continue</font>; 00046 } 00047 <font class="keywordflow">else</font> { 00048 *from <<= 1; 00049 <font class="keywordflow">for</font> (subsequent = 1; (*from & 128); subsequent++) { 00050 *from <<= 1; 00051 from[subsequent] &= 63; 00052 uchar <<= 6; 00053 uchar |= from[subsequent]; 00054 } 00055 subsequent--; 00056 *from <<=1; 00057 significantFirstBits = 8 - (2+subsequent); 00058 00059 uchar |= (((short)*from) << (((6*subsequent)+significantFirstBits)-8)); 00060 from += subsequent; 00061 } 00062 00063 <font class="keywordflow">if</font> (uchar < 0x1ffff) { 00064 *to++ = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>)uchar; 00065 } 00066 <font class="keywordflow">else</font> { 00067 uchar -= 0x10000; 00068 schar = 0xD800 | (uchar & 0x03ff); 00069 uchar >>= 10; 00070 uchar |= 0xDC00; 00071 *to++ = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>)schar; 00072 *to++ = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>)uchar; 00073 } 00074 } 00075 *to = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>)0; 00076 00077 <font class="keywordflow">return</font> 0; 00078 } 00079 </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>