aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/swunicod_8cpp-source.html
blob: 1cb64c18d824ddbed7e469d5e1a3fc756a76760f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!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>swunicod.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>swunicod.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/*</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)</font>
00004 <font class="comment"> *      CrossWire Bible Society</font>
00005 <font class="comment"> *      P. O. Box 2528</font>
00006 <font class="comment"> *      Tempe, AZ  85280-2528</font>
00007 <font class="comment"> *</font>
00008 <font class="comment"> * This program is free software; you can redistribute it and/or modify it</font>
00009 <font class="comment"> * under the terms of the GNU General Public License as published by the</font>
00010 <font class="comment"> * Free Software Foundation version 2.</font>
00011 <font class="comment"> *</font>
00012 <font class="comment"> * This program is distributed in the hope that it will be useful, but</font>
00013 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00014 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU</font>
00015 <font class="comment"> * General Public License for more details.</font>
00016 <font class="comment"> *</font>
00017 <font class="comment"> */</font>
00018 
00019 <font class="preprocessor">#include "swunicod.h"</font>
00020 <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font>* UTF32to8 (<font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> utf32, <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> * utf8) {
00021   <font class="keywordtype">unsigned</font> <font class="keywordtype">int</font> i;
00022   <font class="keywordflow">for</font> (i = 0; i &lt; 6; i++) utf8[i] = 0;
00023 
00024   <font class="keywordflow">if</font> (utf32 &lt; 0x80) {
00025     utf8[0] = (char)utf32;
00026   }
00027   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (utf32 &lt; 0x800) {
00028     i = utf32 &amp; 0x3f;
00029     utf8[1] = 0x80 | i;
00030     utf32 &gt;&gt;= 6;
00031    
00032     i = utf32 &amp; 0x1f;
00033     utf8[0] = 0xc0 | i;
00034   }
00035   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (utf32 &lt; 0x10000) {
00036     i = utf32 &amp; 0x3f;
00037     utf8[2] = 0x80 | i;
00038     utf32 &gt;&gt;= 6;
00039 
00040     i = utf32 &amp; 0x3f;
00041     utf8[1] = 0x80 | i;
00042     utf32 &gt;&gt;= 6;
00043    
00044     i = utf32 &amp; 0x0f;
00045     utf8[0] = 0xe0 | i;
00046   }
00047   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (utf32 &lt; 0x200000) {
00048     i = utf32 &amp; 0x3f;
00049     utf8[3] = 0x80 | i;
00050     utf32 &gt;&gt;= 6;
00051 
00052     i = utf32 &amp; 0x3f;
00053     utf8[2] = 0x80 | i;
00054     utf32 &gt;&gt;= 6;
00055 
00056     i = utf32 &amp; 0x3f;
00057     utf8[1] = 0x80 | i;
00058     utf32 &gt;&gt;= 6;
00059    
00060     i = utf32 &amp; 0x07;
00061     utf8[0] = 0xf0 | i;
00062   }
00063   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (utf32 &lt; 0x4000000) {
00064     i = utf32 &amp; 0x3f;
00065     utf8[4] = 0x80 | i;
00066     utf32 &gt;&gt;= 6;
00067 
00068     i = utf32 &amp; 0x3f;
00069     utf8[3] = 0x80 | i;
00070     utf32 &gt;&gt;= 6;
00071 
00072     i = utf32 &amp; 0x3f;
00073     utf8[2] = 0x80 | i;
00074     utf32 &gt;&gt;= 6;
00075 
00076     i = utf32 &amp; 0x3f;
00077     utf8[1] = 0x80 | i;
00078     utf32 &gt;&gt;= 6;
00079    
00080     i = utf32 &amp; 0x03;
00081     utf8[0] = 0xf8 | i;
00082   }
00083   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (utf32 &lt; 0x80000000) {
00084     i = utf32 &amp; 0x3f;
00085     utf8[5] = 0x80 | i;
00086     utf32 &gt;&gt;= 6;
00087 
00088     i = utf32 &amp; 0x3f;
00089     utf8[4] = 0x80 | i;
00090     utf32 &gt;&gt;= 6;
00091 
00092     i = utf32 &amp; 0x3f;
00093     utf8[3] = 0x80 | i;
00094     utf32 &gt;&gt;= 6;
00095 
00096     i = utf32 &amp; 0x3f;
00097     utf8[2] = 0x80 | i;
00098     utf32 &gt;&gt;= 6;
00099 
00100     i = utf32 &amp; 0x3f;
00101     utf8[1] = 0x80 | i;
00102     utf32 &gt;&gt;= 6;
00103    
00104     i = utf32 &amp; 0x01;
00105     utf8[0] = 0xfc | i;
00106   }
00107   <font class="keywordflow">return</font> utf8;
00108 }
00109 
00114 <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> UTF8to32 (<font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> * utf8) {
00115 
00116   <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> i = utf8[0];
00117   <font class="keywordtype">unsigned</font> <font class="keywordtype">char</font> count;
00118   <font class="keywordtype">unsigned</font> <font class="keywordtype">long</font> utf32 = 0;
00119 
00120   <font class="keywordflow">for</font> (count = 0; i &amp; 0x80; count++) i &lt;&lt;= 1;
00121   <font class="keywordflow">if</font> (!count) {
00122     <font class="keywordflow">return</font> utf8[0];
00123   }
00124   <font class="keywordflow">else</font> <font class="keywordflow">if</font> (count == 1) {
00125     <font class="keywordflow">return</font> 0xffff;
00126   }
00127   <font class="keywordflow">else</font> {
00128     count--;
00129     utf32 = i &gt;&gt; count;
00130     <font class="keywordflow">for</font> (i = 1; i &lt;= count; i++) {
00131       <font class="keywordflow">if</font> (0xc0 &amp; utf8[i] != 0x80) {
00132         <font class="keywordflow">return</font>  0xffff;
00133       }
00134       utf32 &lt;&lt;= 6;
00135       utf32 |= (utf8[i] &amp; 0x3f);
00136     }
00137   }
00138   <font class="keywordflow">return</font> utf32;
00139 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 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>