aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/utf8html_8cpp-source.html
blob: bb703aba9b69527f9ff263029504424b6bd4ea0c (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>utf8html.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>utf8html.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * utf8html -   SWFilter decendant to convert a UTF-8 stream to HTML escapes</font>
00004 <font class="comment"> *</font>
00005 <font class="comment"> */</font>
00006 
00007 
00008 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00009 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00010 <font class="preprocessor">#include &lt;utf8html.h&gt;</font>
00011 
00012 UTF8HTML::UTF8HTML() {
00013 }
00014 
00015 
00016 <font class="keywordtype">char</font> UTF8HTML::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> *to, *from;
00019         <font class="keywordtype">int</font> len;
00020         <font class="keywordtype">char</font> digit[10];
00021         <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> ch;
00022 
00023         len = strlenw(text) + 2;                                                <font class="comment">// shift string to right of buffer</font>
00024         <font class="keywordflow">if</font> (len &lt; maxlen) {
00025                 memmove(&amp;text[maxlen - len], text, len);
00026                 from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)&amp;text[maxlen - len];
00027         }
00028         <font class="keywordflow">else</font>    from = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)text;
00029         <font class="comment">// -------------------------------</font>
00030         <font class="keywordflow">for</font> (to = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)text; *from; from++) {
00031           ch = 0;
00032           <font class="keywordflow">if</font> ((*from &amp; 128) != 128) {
00033 <font class="comment">//              if (*from != ' ')</font>
00034                *to++ = *from;
00035                <font class="keywordflow">continue</font>;
00036           }
00037           <font class="keywordflow">if</font> ((*from &amp; 128) &amp;&amp; ((*from &amp; 64) != 64)) {
00038             <font class="comment">// error</font>
00039                *from = <font class="charliteral">'x'</font>;
00040                <font class="keywordflow">continue</font>;
00041           }
00042           *from &lt;&lt;= 1;
00043           <font class="keywordtype">int</font> subsequent;
00044           <font class="keywordflow">for</font> (subsequent = 1; (*from &amp; 128); subsequent++) {
00045                 *from &lt;&lt;= 1;
00046                from[subsequent] &amp;= 63;
00047                ch &lt;&lt;= 6;
00048                ch |= from[subsequent];
00049           }
00050           subsequent--;
00051           *from &lt;&lt;=1;
00052           <font class="keywordtype">char</font> significantFirstBits = 8 - (2+subsequent);
00053           
00054           ch |= (((short)*from) &lt;&lt; (((6*subsequent)+significantFirstBits)-8));
00055           from += subsequent;
00056           *to++ = <font class="charliteral">'&amp;'</font>;
00057           *to++ = <font class="charliteral">'#'</font>;
00058           sprintf(digit, <font class="stringliteral">"%d"</font>, ch);
00059                 <font class="keywordflow">for</font> (<font class="keywordtype">char</font> *dig = digit; *dig; dig++)
00060                         *to++ = *dig;
00061                 *to++ = <font class="charliteral">';'</font>;
00062         }
00063         *to++ = 0;
00064         *to = 0;
00065         <font class="keywordflow">return</font> 0;
00066 }
</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>