blob: da81d50e8db56df02cf6fa0bf7d28f7240015227 (
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>latin1utf8.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>latin1utf8.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * Latin1UTF8 - SWFilter decendant to convert a Latin-1 character to UTF-8</font>
00004 <font class="comment"> *</font>
00005 <font class="comment"> */</font>
00006
00007
00008 <font class="preprocessor">#include <stdlib.h></font>
00009 <font class="preprocessor">#include <stdio.h></font>
00010 <font class="preprocessor">#include <latin1utf8.h></font>
00011 <font class="preprocessor">#include <swmodule.h></font>
00012
00013 Latin1UTF8::Latin1UTF8() {
00014 }
00015
00016
00017 <font class="keywordtype">char</font> Latin1UTF8::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)
00018 {
00019 <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> *to, *from;
00020 <font class="keywordtype">int</font> len;
00021
00022 len = strlen(text) + 1;
00023 <font class="keywordflow">if</font> (len == maxlen + 1)
00024 maxlen = (maxlen + 1) * FILTERPAD;
00025 <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; <font class="comment">// -------------------------------</font>
00032
00033
00034
00035 <font class="keywordflow">for</font> (to = (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>*)text; *from; from++) {
00036 <font class="keywordflow">if</font> (*from < 0x80) {
00037 *to++ = *from;
00038 }
00039 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (*from < 0xc0) {
00040 <font class="keywordflow">switch</font>(*from) {
00041 <font class="keywordflow">case</font> 0x80: <font class="comment">// ''</font>
00042 *to++ = 0xe2; <font class="comment">// ''</font>
00043 *to++ = 0x82; <font class="comment">// ''</font>
00044 *to++ = 0xac; <font class="comment">// ''</font>
00045 <font class="keywordflow">break</font>;
00046 <font class="keywordflow">case</font> 0x82: <font class="comment">// ''</font>
00047 *to++ = 0xe2; <font class="comment">// ''</font>
00048 *to++ = 0x80; <font class="comment">// ''</font>
00049 *to++ = 0x9a; <font class="comment">// ''</font>
00050 <font class="keywordflow">break</font>;
00051 <font class="keywordflow">case</font> 0x83: <font class="comment">// ''</font>
00052 *to++ = 0xc6; <font class="comment">// ''</font>
00053 *to++ = 0x92; <font class="comment">// ''</font>
00054 <font class="keywordflow">break</font>;
00055 <font class="keywordflow">case</font> 0x84: <font class="comment">// ''</font>
00056 *to++ = 0xe2; <font class="comment">// ''</font>
00057 *to++ = 0x80; <font class="comment">// ''</font>
00058 *to++ = 0x9e; <font class="comment">// ''</font>
00059 <font class="keywordflow">break</font>;
00060 <font class="keywordflow">case</font> 0x85: <font class="comment">// ''</font>
00061 *to++ = 0xe2; <font class="comment">// ''</font>
00062 *to++ = 0x80; <font class="comment">// ''</font>
00063 *to++ = 0xa6; <font class="comment">// ''</font>
00064 <font class="keywordflow">break</font>;
00065 <font class="keywordflow">case</font> 0x86: <font class="comment">// ''</font>
00066 *to++ = 0xe2; <font class="comment">// ''</font>
00067 *to++ = 0x80; <font class="comment">// ''</font>
00068 *to++ = 0xa0; <font class="comment">// ''</font>
00069 <font class="keywordflow">break</font>;
00070 <font class="keywordflow">case</font> 0x87: <font class="comment">// ''</font>
00071 *to++ = 0xe2; <font class="comment">// ''</font>
00072 *to++ = 0x80; <font class="comment">// ''</font>
00073 *to++ = 0xa1; <font class="comment">// ''</font>
00074 <font class="keywordflow">break</font>;
00075 <font class="keywordflow">case</font> 0x88: <font class="comment">// ''</font>
00076 *to++ = 0xcb; <font class="comment">// ''</font>
00077 *to++ = 0x86; <font class="comment">// ''</font>
00078 <font class="keywordflow">break</font>;
00079 <font class="keywordflow">case</font> 0x89: <font class="comment">// ''</font>
00080 *to++ = 0xe2; <font class="comment">// ''</font>
00081 *to++ = 0x80; <font class="comment">// ''</font>
00082 *to++ = 0xb0; <font class="comment">// ''</font>
00083 <font class="keywordflow">break</font>;
00084 <font class="keywordflow">case</font> 0x8A: <font class="comment">// ''</font>
00085 *to++ = 0xc5; <font class="comment">// ''</font>
00086 *to++ = 0xa0; <font class="comment">// ''</font>
00087 <font class="keywordflow">break</font>;
00088 <font class="keywordflow">case</font> 0x8B: <font class="comment">// ''</font>
00089 *to++ = 0xe2; <font class="comment">// ''</font>
00090 *to++ = 0x80; <font class="comment">// ''</font>
00091 *to++ = 0xb9; <font class="comment">// ''</font>
00092 <font class="keywordflow">break</font>;
00093 <font class="keywordflow">case</font> 0x8C: <font class="comment">// ''</font>
00094 *to++ = 0xc5; <font class="comment">// ''</font>
00095 *to++ = 0x92; <font class="comment">// ''</font>
00096 <font class="keywordflow">break</font>;
00097 <font class="keywordflow">case</font> 0x8E: <font class="comment">// ''</font>
00098 *to++ = 0xc5; <font class="comment">// ''</font>
00099 *to++ = 0xbd; <font class="comment">// ''</font>
00100 <font class="keywordflow">break</font>;
00101 <font class="keywordflow">case</font> 0x91: <font class="comment">// ''</font>
00102 *to++ = 0xe2; <font class="comment">// ''</font>
00103 *to++ = 0x80; <font class="comment">// ''</font>
00104 *to++ = 0x98; <font class="comment">// ''</font>
00105 <font class="keywordflow">break</font>;
00106 <font class="keywordflow">case</font> 0x92: <font class="comment">// ''</font>
00107 *to++ = 0xe2; <font class="comment">// ''</font>
00108 *to++ = 0x80; <font class="comment">// ''</font>
00109 *to++ = 0x99; <font class="comment">// ''</font>
00110 <font class="keywordflow">break</font>;
00111 <font class="keywordflow">case</font> 0x93: <font class="comment">// ''</font>
00112 *to++ = 0xe2; <font class="comment">// ''</font>
00113 *to++ = 0x80; <font class="comment">// ''</font>
00114 *to++ = 0x9c; <font class="comment">// ''</font>
00115 <font class="keywordflow">break</font>;
00116 <font class="keywordflow">case</font> 0x94: <font class="comment">// ''</font>
00117 *to++ = 0xe2; <font class="comment">// ''</font>
00118 *to++ = 0x80; <font class="comment">// ''</font>
00119 *to++ = 0x9d; <font class="comment">// ''</font>
00120 <font class="keywordflow">break</font>;
00121 <font class="keywordflow">case</font> 0x95: <font class="comment">// ''</font>
00122 *to++ = 0xe2; <font class="comment">// ''</font>
00123 *to++ = 0x80; <font class="comment">// ''</font>
00124 *to++ = 0xa2; <font class="comment">// ''</font>
00125 <font class="keywordflow">break</font>;
00126 <font class="keywordflow">case</font> 0x96: <font class="comment">// ''</font>
00127 *to++ = 0xe2; <font class="comment">// ''</font>
00128 *to++ = 0x80; <font class="comment">// ''</font>
00129 *to++ = 0x93; <font class="comment">// ''</font>
00130 <font class="keywordflow">break</font>;
00131 <font class="keywordflow">case</font> 0x97: <font class="comment">// ''</font>
00132 *to++ = 0xe2; <font class="comment">// ''</font>
00133 *to++ = 0x80; <font class="comment">// ''</font>
00134 *to++ = 0x94; <font class="comment">// ''</font>
00135 <font class="keywordflow">break</font>;
00136 <font class="keywordflow">case</font> 0x98: <font class="comment">// ''</font>
00137 *to++ = 0xcb; <font class="comment">// ''</font>
00138 *to++ = 0x9c; <font class="comment">// ''</font>
00139 <font class="keywordflow">break</font>;
00140 <font class="keywordflow">case</font> 0x99: <font class="comment">// ''</font>
00141 *to++ = 0xe2; <font class="comment">// ''</font>
00142 *to++ = 0x84; <font class="comment">// ''</font>
00143 *to++ = 0xa2; <font class="comment">// ''</font>
00144 <font class="keywordflow">break</font>;
00145 <font class="keywordflow">case</font> 0x9A: <font class="comment">// ''</font>
00146 *to++ = 0xc5; <font class="comment">// ''</font>
00147 *to++ = 0xa1; <font class="comment">// ''</font>
00148 <font class="keywordflow">break</font>;
00149 <font class="keywordflow">case</font> 0x9B: <font class="comment">// ''</font>
00150 *to++ = 0xe2; <font class="comment">// ''</font>
00151 *to++ = 0x80; <font class="comment">// ''</font>
00152 *to++ = 0xba; <font class="comment">// ''</font>
00153 <font class="keywordflow">break</font>;
00154 <font class="keywordflow">case</font> 0x9C: <font class="comment">// ''</font>
00155 *to++ = 0xc5; <font class="comment">// ''</font>
00156 *to++ = 0x93; <font class="comment">// ''</font>
00157 <font class="keywordflow">break</font>;
00158 <font class="keywordflow">case</font> 0x9E: <font class="comment">// ''</font>
00159 *to++ = 0xc5; <font class="comment">// ''</font>
00160 *to++ = 0xbe; <font class="comment">// ''</font>
00161 <font class="keywordflow">break</font>;
00162 <font class="keywordflow">case</font> 0x9F: <font class="comment">// ''</font>
00163 *to++ = 0xc5; <font class="comment">// ''</font>
00164 *to++ = 0xb8; <font class="comment">// ''</font>
00165 <font class="keywordflow">break</font>;
00166 <font class="keywordflow">default</font>:
00167 *to++ = 0xC2;
00168 *to++ = *from;
00169 }
00170 }
00171 <font class="keywordflow">else</font> {
00172 *to++ = 0xC3;
00173 *to++ = (*from - 0x40);
00174 }
00175 }
00176 *to++ = 0;
00177 *to = 0;
00178 <font class="keywordflow">return</font> 0;
00179 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:12:59 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>
|