3
* Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
4
* CrossWire Bible Society
8
* This program is free software; you can redistribute it and/or modify it
9
* under the terms of the GNU General Public License as published by the
10
* Free Software Foundation version 2.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
21
unsigned char* UTF32to8 (unsigned long utf32, unsigned char * utf8) {
23
for (i = 0; i < 6; i++) utf8[i] = 0;
26
utf8[0] = (char)utf32;
28
else if (utf32 < 0x800) {
36
else if (utf32 < 0x10000) {
48
else if (utf32 < 0x200000) {
64
else if (utf32 < 0x4000000) {
84
else if (utf32 < 0x80000000) {
111
unsigned long UTF8to32 (unsigned char * utf8) {
113
unsigned char i = utf8[0];
115
unsigned long utf32 = 0;
117
for (count = 0; i & 0x80; count++) i <<= 1;
121
else if (count == 1) {
127
for (i = 1; i <= count; i++) {
128
if (0xc0 & utf8[i] != 0x80) {
132
utf32 |= (utf8[i] & 0x3f);