aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/utf8latin1_8cpp-source.html
blob: cf89e04fdb9c47beab88e644ecb28533db9d51a4 (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>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> &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>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 &lt;stdlib.h&gt;</font>
00008 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00009 
00010 <font class="preprocessor">#include &lt;utf8latin1.h&gt;</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 &lt; maxlen) {
00027     memmove(&amp;text[maxlen - len], text, len);
00028     from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)&amp;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 &amp; 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 &amp; 128) &amp;&amp; ((*from &amp; 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 &lt;&lt;= 1;
00048       <font class="keywordflow">for</font> (subsequent = 1; (*from &amp; 128); subsequent++) {
00049         *from &lt;&lt;= 1;
00050         from[subsequent] &amp;= 63;
00051         uchar &lt;&lt;= 6;
00052         uchar |= from[subsequent];
00053       }
00054       subsequent--;
00055       *from &lt;&lt;=1;
00056       significantFirstBits = 8 - (2+subsequent);
00057       
00058       uchar |= (((short)*from) &lt;&lt; (((6*subsequent)+significantFirstBits)-8));
00059       from += subsequent;
00060     }
00061 
00062     <font class="keywordflow">if</font> (uchar &lt; 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>