update to 0.19.5
[platform/upstream/fribidi.git] / charset / fribidi-char-sets-iso8859-8.c
1 /* FriBidi
2  * fribidi-char-sets-iso8859-8.c - ISO8859-8 character set conversion routines
3  *
4  * $Id: fribidi-char-sets-iso8859-8.c,v 1.2 2004-05-03 22:05:19 behdad Exp $
5  * $Author: behdad $
6  * $Date: 2004-05-03 22:05:19 $
7  * $Revision: 1.2 $
8  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/charset/fribidi-char-sets-iso8859-8.c,v $
9  *
10  * Authors:
11  *   Behdad Esfahbod, 2001, 2002, 2004
12  *   Dov Grobgeld, 1999, 2000
13  *
14  * Copyright (C) 2004 Sharif FarsiWeb, Inc
15  * Copyright (C) 2001,2002 Behdad Esfahbod
16  * Copyright (C) 1999,2000 Dov Grobgeld
17  * 
18  * This library is free software; you can redistribute it and/or
19  * modify it under the terms of the GNU Lesser General Public
20  * License as published by the Free Software Foundation; either
21  * version 2.1 of the License, or (at your option) any later version.
22  * 
23  * This library is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26  * Lesser General Public License for more details.
27  * 
28  * You should have received a copy of the GNU Lesser General Public License
29  * along with this library, in a file named COPYING; if not, write to the
30  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
31  * Boston, MA 02110-1301, USA
32  * 
33  * For licensing issues, contact <license@farsiweb.info>.
34  */
35
36 #include <common.h>
37
38 #include <fribidi-char-sets-iso8859-8.h>
39
40 #include <fribidi-unicode.h>
41
42 /* The following are proposed extensions to ISO8859-8. */
43 #define ISO_8859_8_LRM          0xFD
44 #define ISO_8859_8_RLM          0xFE
45 #define ISO_8859_8_LRE          0xFB
46 #define ISO_8859_8_RLE          0xFC
47 #define ISO_8859_8_PDF          0xDD
48 #define ISO_8859_8_LRO          0xDB
49 #define ISO_8859_8_RLO          0xDC
50 #define ISO_ALEF                0xE0
51 #define ISO_TAV                 0xFA
52
53 #define UNI_ALEF                0x05D0
54 #define UNI_TAV                 0x05EA
55
56 FriBidiChar
57 fribidi_iso8859_8_to_unicode_c (
58   /* input */
59   char sch
60 )
61 {
62   register unsigned char ch = (unsigned char) sch;
63   if (ch < ISO_8859_8_LRO)
64     return ch;
65   else if (ch >= ISO_ALEF && ch <= ISO_TAV)
66     return ch - ISO_ALEF + UNI_ALEF;
67   switch (ch)
68     {
69     case ISO_8859_8_RLM:
70       return FRIBIDI_CHAR_RLM;
71     case ISO_8859_8_LRM:
72       return FRIBIDI_CHAR_LRM;
73     case ISO_8859_8_RLO:
74       return FRIBIDI_CHAR_RLO;
75     case ISO_8859_8_LRO:
76       return FRIBIDI_CHAR_LRO;
77     case ISO_8859_8_RLE:
78       return FRIBIDI_CHAR_RLE;
79     case ISO_8859_8_LRE:
80       return FRIBIDI_CHAR_LRE;
81     case ISO_8859_8_PDF:
82       return FRIBIDI_CHAR_PDF;
83     default:
84       return '?';
85     }
86 }
87
88 char
89 fribidi_unicode_to_iso8859_8_c (
90   /* input */
91   FriBidiChar uch
92 )
93 {
94   if (uch < 128)
95     return (char) uch;
96   if (uch >= UNI_ALEF && uch <= UNI_TAV)
97     return (char) (uch - UNI_ALEF + ISO_ALEF);
98   switch (uch)
99     {
100     case FRIBIDI_CHAR_RLM:
101       return (char) ISO_8859_8_RLM;
102     case FRIBIDI_CHAR_LRM:
103       return (char) ISO_8859_8_LRM;
104     case FRIBIDI_CHAR_RLO:
105       return (char) ISO_8859_8_RLO;
106     case FRIBIDI_CHAR_LRO:
107       return (char) ISO_8859_8_LRO;
108     case FRIBIDI_CHAR_RLE:
109       return (char) ISO_8859_8_RLE;
110     case FRIBIDI_CHAR_LRE:
111       return (char) ISO_8859_8_LRE;
112     case FRIBIDI_CHAR_PDF:
113       return (char) ISO_8859_8_PDF;
114     }
115   return '?';
116 }
117
118 /* Editor directions:
119  * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
120  */