<!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>utf8latin1.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>utf8latin1.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font> 00002 <font class="comment"> *</font> 00003 <font class="comment"> * UTF8Latin1 - SWFilter decendant to convert UTF-8 to Latin-1</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 <utf8latin1.h></font> 00011 00012 UTF8Latin1::UTF8Latin1(<font class="keywordtype">char</font> rchar) : replacementChar(rchar) { 00013 } 00014 00015 00016 <font class="keywordtype">char</font> UTF8Latin1::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 00025 len = strlen(text) + 1; <font class="comment">// shift string to right of buffer</font> 00026 <font class="keywordflow">if</font> (len < maxlen) { 00027 memmove(&text[maxlen - len], text, len); 00028 from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)&text[maxlen - len]; 00029 } 00030 <font class="keywordflow">else</font> 00031 from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)text; 00032 00033 00034 <font class="comment">// -------------------------------</font> 00035 00036 <font class="keywordflow">for</font> (to = (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>*)text; *from; from++) { 00037 uchar = 0; 00038 <font class="keywordflow">if</font> ((*from & 128) != 128) { 00039 <font class="comment">// if (*from != ' ')</font> 00040 uchar = *from; 00041 } 00042 <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((*from & 128) && ((*from & 64) != 64)) { 00043 <font class="comment">// error, do nothing</font> 00044 <font class="keywordflow">continue</font>; 00045 } 00046 <font class="keywordflow">else</font> { 00047 *from <<= 1; 00048 <font class="keywordflow">for</font> (subsequent = 1; (*from & 128); subsequent++) { 00049 *from <<= 1; 00050 from[subsequent] &= 63; 00051 uchar <<= 6; 00052 uchar |= from[subsequent]; 00053 } 00054 subsequent--; 00055 *from <<=1; 00056 significantFirstBits = 8 - (2+subsequent); 00057 00058 uchar |= (((short)*from) << (((6*subsequent)+significantFirstBits)-8)); 00059 from += subsequent; 00060 } 00061 00062 <font class="keywordflow">if</font> (uchar < 0xff) { 00063 *to++ = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>)uchar; 00064 } 00065 <font class="keywordflow">else</font> { 00066 *to++ = replacementChar; 00067 } 00068 } 00069 *to++ = 0; 00070 *to = 0; 00071 00072 <font class="keywordflow">return</font> 0; 00073 } 00074 </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>