Imported Upstream version 0.19.4
[platform/upstream/fribidi.git] / charset / fribidi-char-sets-cp1255.c
1 /* FriBidi
2  * fribidi-char-sets-cp1255.c - CP1255 character set conversion routines
3  *
4  * $Id: fribidi-char-sets-cp1255.c,v 1.3 2008-04-22 19:50:46 behdad Exp $
5  * $Author: behdad $
6  * $Date: 2008-04-22 19:50:46 $
7  * $Revision: 1.3 $
8  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/charset/fribidi-char-sets-cp1255.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., 59 Temple Place, Suite 330,
31  * Boston, MA 02111-1307, USA
32  * 
33  * For licensing issues, contact <license@farsiweb.info>.
34  */
35
36 #include <common.h>
37
38 #include <fribidi-char-sets-cp1255.h>
39
40 #define ISO_ALEF                0xE0
41 #define ISO_TAV                 0xFA
42 #define CP1255_SHEVA            0xC0
43 #define CP1255_SOF_PASUQ        0xD3
44 #define CP1255_DOUBLE_VAV       0xD4
45 #define CP1255_GERSHAYIM        0xD8
46 #define CP1255_LRM              0xFD
47 #define CP1255_RLM              0xFE
48
49 #define UNI_ALEF                0x05D0
50 #define UNI_TAV                 0x05EA
51 #define UNI_SHEVA               0x05B0
52 #define UNI_SOF_PASUQ           0x05C3
53 #define UNI_DOUBLE_VAV          0x05F0
54 #define UNI_GERSHAYIM           0x05F4
55 #define UNI_LRM                 0x200E
56 #define UNI_RLM                 0x200F
57
58 static FriBidiChar fribidi_cp1255_to_unicode_tab[] = {  /* 0x80-0xBF */
59   0x20AC, 0x0081, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
60   0x02C6, 0x2030, 0x008a, 0x2039, 0x008c, 0x008d, 0x008e, 0x008f,
61   0x0090, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
62   0x02DC, 0x2122, 0x009a, 0x203A, 0x009c, 0x009d, 0x009e, 0x009f,
63   0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AA, 0x00A5, 0x00A6, 0x00A7,
64   0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
65   0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
66   0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF
67 };
68
69 FriBidiChar
70 fribidi_cp1255_to_unicode_c (
71   /* input */
72   char sch
73 )
74 {
75   register unsigned char ch = (unsigned char) sch;
76   if (ch >= ISO_ALEF && ch <= ISO_TAV)
77     return ch - ISO_ALEF + UNI_ALEF;
78   else if (ch >= CP1255_SHEVA && ch <= CP1255_SOF_PASUQ)
79     return ch - CP1255_SHEVA + UNI_SHEVA;
80   else if (ch >= CP1255_DOUBLE_VAV && ch <= CP1255_GERSHAYIM)
81     return ch - CP1255_DOUBLE_VAV + UNI_DOUBLE_VAV;
82   /* cp1256 specific chars */
83   else if (ch >= 0x80 && ch <= 0xbf)
84     return fribidi_cp1255_to_unicode_tab[ch - 0x80];
85   else if (ch == CP1255_LRM || ch == CP1255_RLM) 
86     return ch - CP1255_LRM + UNI_LRM;
87     /* treat LRM/LRM charrectes correctly */
88   else 
89     return ch;
90 }
91
92 char
93 fribidi_unicode_to_cp1255_c (
94   /* input */
95   FriBidiChar uch
96 )
97 {
98   if (uch >= UNI_ALEF && uch <= UNI_TAV)
99     return (char) (uch - UNI_ALEF + ISO_ALEF);
100   if (uch >= UNI_SHEVA && uch <= UNI_SOF_PASUQ)
101     return (char) (uch - UNI_SHEVA + CP1255_SHEVA);
102   if (uch >= UNI_DOUBLE_VAV && uch <= UNI_GERSHAYIM)
103     return (char) (uch - UNI_DOUBLE_VAV + CP1255_DOUBLE_VAV);
104   /* TODO: handle pre-composed and presentation chars */
105   if (uch == UNI_LRM || uch==UNI_RLM)
106     return (char) (uch - UNI_LRM + CP1255_LRM);
107     /* Treat LRM/RLM charrecters correctly */
108   else if (uch < 256)
109     return (char) uch;
110   else
111     return '?';
112 }
113
114 /* Editor directions:
115  * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
116  */