aboutsummaryrefslogblamecommitdiffstats
path: root/doc/api-documentation/html/unicodertf_8cpp-source.html
blob: 6b2fd2c91afd918bc5d75eda32e06fadf1006059 (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>unicodertf.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>unicodertf.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * unicodertf - SWFilter decendant to convert a double byte unicode file</font>
00004 <font class="comment"> *                               to RTF tags</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;unicodertf.h&gt;</font>
00011 
00012 UnicodeRTF::UnicodeRTF() {
00013 }
00014 
00015 
00016 <font class="keywordtype">char</font> UnicodeRTF::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, *maxto;
00019         <font class="keywordtype">int</font> len;
00020         <font class="keywordtype">char</font> digit[10];
00021         <font class="keywordtype">short</font> ch;       <font class="comment">// must be signed per unicode spec (negative is ok for big numbers &gt; 32768)</font>
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         maxto =(<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)text + maxlen;
00030 
00031         <font class="comment">// -------------------------------</font>
00032         <font class="keywordtype">bool</font> lastUni = <font class="keyword">false</font>;
00033         <font class="keywordflow">for</font> (to = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)text; *from &amp;&amp; (to &lt;= maxto); from++) {
00034                 ch = 0;
00035                 <font class="keywordflow">if</font> ((*from &amp; 128) != 128) {
00036 <font class="comment">//                      if ((*from == ' ') &amp;&amp; (lastUni))</font>
00037 <font class="comment">//                              *to++ = ' ';</font>
00038                         *to++ = *from;
00039                         lastUni = <font class="keyword">false</font>;
00040                         <font class="keywordflow">continue</font>;
00041                 }
00042                 <font class="keywordflow">if</font> ((*from &amp; 128) &amp;&amp; ((*from &amp; 64) != 64)) {
00043             <font class="comment">// error</font>
00044                         *from = <font class="charliteral">'x'</font>;
00045                         <font class="keywordflow">continue</font>;
00046                 }
00047                 *from &lt;&lt;= 1;
00048                 <font class="keywordtype">int</font> subsequent;
00049                 <font class="keywordflow">for</font> (subsequent = 1; (*from &amp; 128); subsequent++) {
00050                         *from &lt;&lt;= 1;
00051                         from[subsequent] &amp;= 63;
00052                         ch &lt;&lt;= 6;
00053                         ch |= from[subsequent];
00054                 }
00055                 subsequent--;
00056                 *from &lt;&lt;=1;
00057                 <font class="keywordtype">char</font> significantFirstBits = 8 - (2+subsequent);
00058                 
00059                 ch |= (((short)*from) &lt;&lt; (((6*subsequent)+significantFirstBits)-8));
00060                 from += subsequent;
00061                 *to++ = <font class="charliteral">'\\'</font>;
00062                 *to++ = <font class="charliteral">'u'</font>;
00063                 sprintf(digit, <font class="stringliteral">"%d"</font>, ch);
00064                 <font class="keywordflow">for</font> (<font class="keywordtype">char</font> *dig = digit; *dig; dig++)
00065                         *to++ = *dig;
00066                 *to++ = <font class="charliteral">'?'</font>;
00067                 lastUni = <font class="keyword">true</font>;
00068         }
00069            
00070         <font class="keywordflow">if</font> (to != maxto) {
00071                 *to++ = 0;
00072         }
00073         *to = 0;
00074         <font class="keywordflow">return</font> 0;
00075 }
</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>