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
|
module CPM.Helpers ( stripSpaces, stripEnclosing, askYesNo ) where
import Data.Char ( isSpace, toLower )
import Data.List ( init, isPrefixOf, last )
import System.IO ( hFlush, stdout )
stripSpaces :: String -> String
stripSpaces = reverse . dropWhile isSpace . reverse . dropWhile isSpace
stripEnclosing :: Char -> Char -> String -> String
stripEnclosing lc tc s = case s of
c1:cs@(_:_) | c1 == lc && last cs == tc -> init cs
_ -> s
askYesNo :: String -> IO String
askYesNo question = do
putStr question
hFlush stdout
answer <- fmap (map toLower) getLine
if null answer
then return answer
else if answer `isPrefixOf` "yes"
then return "yes"
else if answer `isPrefixOf` "no"
then return "no"
else askYesNo question
|