summaryrefslogtreecommitdiff
path: root/src/GF/Text/Arabic.hs
blob: 1b829981ff2e6fac73885e2c8059777d8ed8b9a8 (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
----------------------------------------------------------------------
-- |
-- Module      : Arabic
-- Maintainer  : (Maintainer)
-- Stability   : (stable)
-- Portability : (portable)
--
-- > CVS $Date: 2005/02/18 19:21:13 $ 
-- > CVS $Author: peb $
-- > CVS $Revision: 1.5 $
--
-- (Description of the module)
-----------------------------------------------------------------------------

module Arabic (mkArabic) where

mkArabic :: String -> String
mkArabic = unwords . (map mkArabicWord) . words
----mkArabic = reverse . unwords . (map mkArabicWord) . words
--- reverse : assumes everything's on same line

type ArabicChar = Char

mkArabicWord :: String -> [ArabicChar]
mkArabicWord = map mkArabicChar . getLetterPos

getLetterPos :: String -> [(Char,Int)]
getLetterPos []     = []
getLetterPos ('I':cs)  = ('*',7) : getLetterPos cs           -- 0xfe80
getLetterPos ('O':cs)  = ('*',8) : getIn cs                  -- 0xfe8b
getLetterPos ('l':'a':cs) = ('*',5) : getLetterPos cs        -- 0xfefb
getLetterPos [c]    = [(c,1)]                                -- 1=isolated
getLetterPos (c:cs) | isReduced c = (c,1) : getLetterPos cs
getLetterPos (c:cs) = (c,3) : getIn cs                       -- 3=initial

  
getIn []     = []
getIn ('I':cs)  = ('*',7) : getLetterPos cs                -- 0xfe80
getIn ('O':cs)  = ('*',9) : getIn cs                       -- 0xfe8c
getIn ('l':'a':cs) = ('*',6) : getLetterPos cs             -- 0xfefc
getIn [c]    = [(c,2)]                                     -- 2=final
getIn (c:cs) | isReduced c = (c,2) : getLetterPos cs
getIn (c:cs) = (c,4) : getIn cs                            -- 4=medial

isReduced :: Char -> Bool
isReduced c = c `elem` "UuWiYOaAdVrzwj"

mkArabicChar ('*',p) | p > 4 && p < 10 = 
  (map toEnum [0xfefb,0xfefc,0xfe80,0xfe8b,0xfe8c]) !! (p-5)  
mkArabicChar cp@(c,p) = case lookup c cc of Just c' -> (c' !! (p-1)) ; _ -> c 
 where 
   cc = mkArabicTab allArabicCodes allArabic

mkArabicTab (c:cs) as = (c,as1) : mkArabicTab cs as2 where
  (as1,as2) = if isReduced c then splitAt 2 as else splitAt 4 as
mkArabicTab [] _ = []

allArabicCodes = "UuWiYOabAtvgHCdVrzscSDTZoxfqklmnhwjy" 

allArabic :: String
allArabic = (map toEnum [0xfe81 .. 0xfef4]) -- I=0xfe80