Skip to content

Instantly share code, notes, and snippets.

@alogic0
Last active December 9, 2016 04:27
Show Gist options
  • Save alogic0/8f1a5fcde7051ea79856876452c5a8fd to your computer and use it in GitHub Desktop.
Save alogic0/8f1a5fcde7051ea79856876452c5a8fd to your computer and use it in GitHub Desktop.
Convert mistyped text from English keyboard to Russian
import Data.Maybe (maybe)
import Data.Char (toUpper)
import System.IO (hGetContents, stdin)
import Control.Monad (liftM, forM_)
ruKeysL = "ёйцукенгшщзхъфывапролджэячсмитьбю"
ruKeysU = map toUpper ruKeysL
ruKeysP = ".,"
enKeysL = "`qwertyuiop[]asdfghjkl;\'zxcvbnm,."
enKeysU = "~QWERTYUIOP{}ASDFGHJKL:\"ZXCVBNM<>"
enKeysP = "/?"
ruKeys = ruKeysL ++ ruKeysU ++ ruKeysP
enKeys = enKeysL ++ enKeysU ++ enKeysP
en2ruChar :: Char -> Char
en2ruChar c = maybe c id (lookup c (zip enKeys ruKeys))
en2ruStr :: String -> String
en2ruStr = map en2ruChar
en2ru :: String -> IO ()
en2ru = putStrLn . en2ruStr
main :: IO ()
main =
do putStrLn "Paste your text here"
putStrLn "Print in the end this line: 'xxx'"
input' <- liftM lines (hGetContents stdin)
-- weird construction to postpone output until input is fully recieved
if elem "xxx" input'
then return ()
else return ()
let input = takeWhile (/= "xxx") input'
forM_ input en2ru
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment