packages feed

deunicode-0.1: deunicode.hs

import Prelude (return,otherwise,(>>),(>>=),(<),Maybe(..))
import Data.Char (ord,isAscii)
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Lazy.UTF8 as U
import qualified System.IO as S

expand_haskell_op c = case ord c of
  0x00AC -> S.putStr "not"		{- NOT SIGN -}
  0x00F7 -> S.putStr "/"		{- DIVISION SIGN -}
  0x03B1 -> S.putStr "a"		{- GREEK SMALL LETTER ALPHA -}
  0x03B2 -> S.putStr "b"		{- GREEK SMALL LETTER BETA -}
  0x03B3 -> S.putStr "c"		{- GREEK SMALL LETTER GAMMA -}
  0x03B4 -> S.putStr "d"		{- GREEK SMALL LETTER DELTA -}
  0x03B5 -> S.putStr "epsilon"		{- GREEK SMALL LETTER EPSILON -}
  0x03C0 -> S.putStr "pi"		{- GREEK SMALL LETTER PI -}
  0x2042 -> S.putStr "***"		{- ASTERISM -}
  0x2190 -> S.putStr "<-"		{- LEFTWARDS ARROW -}
  0x2192 -> S.putStr "->"		{- RIGHTWARDS ARROW -}
  0x21D0 -> S.putStr "<="		{- LEFTWARDS DOUBLE ARROW -}
  0x21D2 -> S.putStr "=>"		{- RIGHTWARDS DOUBLE ARROW -}
  0x2200 -> S.putStr "forall"		{- FOR ALL -}
  0x2208 -> S.putStr "`elem`"		{- ELEMENT OF -}
  0x2209 -> S.putStr "`notElem`"	{- NOT AN ELEMENT OF -}
  0x2216 -> S.putStr "\\\\"		{- SET MINUS -}
  0x2218 -> S.putStr "."		{- RING OPERATOR -}
  0x2227 -> S.putStr "&&"		{- LOGICAL AND -}
  0x2228 -> S.putStr "||"		{- LOGICAL OR -}
  0x2229 -> S.putStr "`intersect`"	{- INTERSECTION -}
  0x222A -> S.putStr "`union`"		{- UNION -}
  0x2237 -> S.putStr "::"		{- PROPORTION -}
  0x2260 -> S.putStr "/="		{- NOT EQUAL TO -}
  0x2261 -> S.putStr "=="		{- IDENTICAL TO -}
  0x2262 -> S.putStr "/="		{- NOT IDENTICAL TO -}
  0x2264 -> S.putStr "<="		{- LESS-THAN OR EQUAL TO -}
  0x2265 -> S.putStr ">="		{- GREATER-THAN OR EQUAL TO -}
  0x226B -> S.putStr ">>"		{- MUCH GREATER-THAN -}
  0x226E -> S.putStr ">="		{- NOT LESS-THAN -}
  0x226F -> S.putStr "<="		{- NOT GREATER-THAN -}
  0x2295 -> S.putStr "`mappend`"	{- CIRCLED PLUS -}
  0x229B -> S.putStr "<*>"		{- CIRCLED ASTERISK OPERATOR -}
  0x22A5 -> S.putStr "undefined"	{- UP TACK -}
  0x22C5 -> S.putStr "*"		{- DOT OPERATOR -}
  0x22D8 -> S.putStr "<<<"		{- VERY MUCH LESS-THAN -}
  0x22D9 -> S.putStr ">>>"		{- VERY MUCH GREATER-THAN -}
  0x29FA -> S.putStr "++"		{- DOUBLE PLUS -}
  0x29FB -> S.putStr "+++"		{- TRIPLE PLUS -}
  0x2AF4 -> S.putStr "|||"		{- TRIPLE VERTICAL BAR BINARY RELATION -}
  _      -> S.putChar c

deunicode s
  | B.null s  = return ()
  | otherwise = B.putStr ascii >> deunicode' rest
  where
    (ascii,rest) = U.span isAscii s

deunicode' s = expand nonascii >> deunicode rest
  where
    (nonascii,rest) = U.break isAscii s

expand s = case U.decode s of
  Nothing       -> return ()
  Just (c,rest) -> expand_haskell_op c

main = B.getContents >>= deunicode