module Utils.Drasil.English (capitalize, stringList) where
import Data.Char (toLower, toUpper)
capitalize :: String -> String
capitalize :: String -> String
capitalize [] = String -> String
forall a. HasCallStack => String -> a
error String
"capitalize called on an empty String"
capitalize (Char
c:String
cs) = Char -> Char
toUpper Char
cChar -> String -> String
forall a. a -> [a] -> [a]
:(Char -> Char) -> String -> String
forall a b. (a -> b) -> [a] -> [b]
map Char -> Char
toLower String
cs
stringList :: [String] -> String
stringList :: [String] -> String
stringList [String]
s = [String] -> String
mkStr ((String -> Bool) -> [String] -> [String]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (String -> Bool) -> String -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null) [String]
s)
where
mkStr :: [String] -> String
mkStr :: [String] -> String
mkStr [] = String
""
mkStr [String
d] = String
d
mkStr [String
d1, String
d2] = String
d1 String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
" and " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
d2
mkStr (String
d:[String]
ds) = String
d String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
manyStrs [String]
ds
manyStrs :: [String] -> String
manyStrs :: [String] -> String
manyStrs [] = String -> String
forall a. HasCallStack => String -> a
error String
"impossible case in manyStrs"
manyStrs [String
d] = String
", and " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
d
manyStrs (String
d:[String]
ds) = String
", " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
d String -> String -> String
forall a. [a] -> [a] -> [a]
++ [String] -> String
manyStrs [String]
ds