Commit 7cdd8d2a authored by Nicolas Lenz's avatar Nicolas Lenz
Browse files

Move styles into Lib

parent 6b2651b1
module Main where
import Mock
import Mock (styles)
import Data.List
import Data.Char
import Data.Maybe
......@@ -25,22 +25,6 @@ handle (style:text) = transform (dropWhileEnd isSpace (intercalate " " text)) >>
Just f -> f -- Use the found style function
Nothing -> const $ return help -- If the style isn't found, always return just the help string
-- |List of possible mock styles names and their functions.
styles :: [(String, String -> IO String)]
styles = [
("random", mockRandom),
("alternate", toIO mockAlternate),
("space", toIO $ letterspace 1),
("space2", toIO $ letterspace 2),
("space3", toIO $ letterspace 3),
("upper", toIO $ map toUpper),
("lower", toIO $ map toLower),
("double", toIO $ map toDS)]
-- |Lifts a simple function into an IO operation simply returning what the function would return.
toIO :: (a -> b) -> (a -> IO b)
toIO f = \x -> return $ f x
-- |Help string.
help :: String
help = "Mock - a program to transform text.\n\
......
module Mock (mockAlternate, mockRandom, letterspace, toDS) where
module Mock (styles, mockAlternate, mockRandom, letterspace, toDS) where
import Data.Char
import Data.List
......@@ -6,6 +6,22 @@ import System.Random
import Data.Time.Clock.POSIX
-- |List of possible mock style names and their functions.
styles :: [(String, String -> IO String)]
styles = [
("random", mockRandom),
("alternate", toIO mockAlternate),
("space", toIO $ letterspace 1),
("space2", toIO $ letterspace 2),
("space3", toIO $ letterspace 3),
("upper", toIO $ map toUpper),
("lower", toIO $ map toLower),
("double", toIO $ map toDS)]
-- |Lifts a simple function into an IO operation simply returning what the function would return.
toIO :: (a -> b) -> (a -> IO b)
toIO f = \x -> return $ f x
-- |Transforms a String into uppercase where the corresponding list is True. For False the String isn't changed.
toUpperBy :: String -> [Bool] -> String
toUpperBy (c:cs) (True:bs) = toUpper c : toUpperBy cs bs
......@@ -27,6 +43,7 @@ mockRandom str = do
letterspace :: Int -> String -> String
letterspace n = intercalate (replicate n ' ') . map (\c -> [c])
-- |Transforms a character into its double-struck variant (if it is alphanumeric).
toDS :: Char -> Char
toDS 'C' = chr 8450
toDS 'H' = chr 8461
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment