blob: d447c9af2da4d0e6a2d99f6d6bbb282060794f5c (
plain)
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
|
// Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
#include <config.h>
#include <stdio.h>
#include "iso88598.h"
#include "univalues.h"
#define ISO88598_HEB_ALEF 0xE0
#define ISO88598_HEB_TAV 0xFA
// The following 7 codes were taken from FriBiDi's fribidi_char_sets_iso8859_8.c.
// These are "proposed extensions to ISO-8859-8."
#define ISO88598_LRM 0xFD
#define ISO88598_RLM 0xFE
#define ISO88598_LRE 0xFB
#define ISO88598_RLE 0xFC
#define ISO88598_PDF 0xDD
#define ISO88598_LRO 0xDB
#define ISO88598_RLO 0xDC
// int unicode_to_iso88598(unichar ch)
//
// This is a fallback function used for saving files when no iconv
// implementation is present.
//
// It returns EOF when the unicode character can't be represented in
// ISO-8859-9.
int unicode_to_iso88598(unichar ch)
{
if (ch <= 0xA0)
return ch;
if (ch >= UNI_HEB_ALEF && ch <= UNI_HEB_TAV)
return ISO88598_HEB_ALEF + (ch - UNI_HEB_ALEF);
switch (ch) {
case 0x00D7: return 0xAA; // MULTIPLICATION SIGN
case 0x00F7: return 0xBA; // DIVISION SIGN
case 0x2017: return 0xDF; // DOUBLE LOW LINE
}
if (ch >= 0xA2 && ch <= 0xBE)
return ch;
// The following are non-standard conversions.
switch (ch) {
case UNI_LRM: return ISO88598_LRM;
case UNI_RLM: return ISO88598_RLM;
case UNI_LRE: return ISO88598_LRE;
case UNI_RLE: return ISO88598_RLE;
case UNI_PDF: return ISO88598_PDF;
case UNI_LRO: return ISO88598_LRO;
case UNI_RLO: return ISO88598_RLO;
}
return EOF;
}
// unichar iso88598_to_unicode(unsigned char ch)
//
// This is a fallback function used for loading files when no iconv
// implementation is present.
//
// It returns the Unicode Replacement Character when it encounters a
// character which is illegal in ISO-8859-9.
unichar iso88598_to_unicode(unsigned char ch)
{
if (ch <= 0xA0)
return ch;
if (ch >= ISO88598_HEB_ALEF && ch <= ISO88598_HEB_TAV)
return UNI_HEB_ALEF + (ch - ISO88598_HEB_ALEF);
switch (ch) {
case 0xAA: return 0x00D7; // MULTIPLICATION SIGN
case 0xBA: return 0x00F7; // DIVISION SIGN
case 0xDF: return 0x2017; // DOUBLE LOW LINE
}
if (ch >= 0xA2 && ch <= 0xBE)
return ch;
// The following are non-standard conversions.
switch (ch) {
case ISO88598_LRM: return UNI_LRM;
case ISO88598_RLM: return UNI_RLM;
case ISO88598_LRE: return UNI_LRE;
case ISO88598_RLE: return UNI_RLE;
case ISO88598_PDF: return UNI_PDF;
case ISO88598_LRO: return UNI_LRO;
case ISO88598_RLO: return UNI_RLO;
}
return UNI_REPLACEMENT;
}
|