tools/confuse.hs
changeset 10064 bf1a5ef4ef14
child 10073 865a4089278d
equal deleted inserted replaced
10063:52e293f14977 10064:bf1a5ef4ef14
       
     1 {-# LANGUAGE OverloadedStrings #-}
       
     2 module Confuse where
       
     3 
       
     4 import Numeric
       
     5 import Data.Char
       
     6 import Control.Monad
       
     7 import qualified Data.ByteString as B
       
     8 import qualified Data.ByteString.UTF8 as UTF8
       
     9 
       
    10 hx :: [Char] -> String
       
    11 hx cs = let ch = (chr . fst . last . readHex $ cs) in
       
    12             case ch of
       
    13                  '\'' -> "''"
       
    14                  '\\' -> "\\\\"
       
    15                  c -> c : []
       
    16 
       
    17 conv :: String -> B.ByteString
       
    18 conv s = B.concat ["('", UTF8.fromString i, "', '", UTF8.fromString r, "')"]
       
    19     where
       
    20         i :: String
       
    21         i = hx s
       
    22         r :: String
       
    23         r = concatMap hx . words . takeWhile ((/=) ';') . tail $ dropWhile ((/=) '\t') s
       
    24 
       
    25 main = do
       
    26     ll <- liftM (filter (isHexDigit . head) . filter (not . null) . lines) $ readFile "confusables.txt"
       
    27     B.writeFile "insert.sql" . B.intercalate ",\n" . map conv $ ll