2022-04-19 10:50:02 +03:00
|
|
|
module TitleCase (titleCase) where
|
|
|
|
|
|
|
|
import qualified Data.Char as Char
|
|
|
|
|
|
|
|
titleCase :: String -> String -> String
|
2022-04-19 22:43:15 +03:00
|
|
|
titleCase minor = unwords . process . words . toLower
|
2022-04-19 10:50:02 +03:00
|
|
|
where
|
2022-04-19 22:43:15 +03:00
|
|
|
process :: [String] -> [String]
|
|
|
|
process [] = []
|
|
|
|
process (head:tail) = toTitle head : map maybeToTitle tail
|
|
|
|
|
|
|
|
lowerMinorWords :: [String]
|
|
|
|
lowerMinorWords = words $ toLower minor
|
2022-04-19 10:50:02 +03:00
|
|
|
|
|
|
|
maybeToTitle :: String -> String
|
|
|
|
maybeToTitle word
|
2022-04-19 22:43:15 +03:00
|
|
|
| word `elem` lowerMinorWords = word
|
|
|
|
| otherwise = toTitle word
|
2022-04-19 10:50:02 +03:00
|
|
|
|
|
|
|
toTitle :: String -> String
|
2022-04-19 22:43:15 +03:00
|
|
|
toTitle [] = []
|
|
|
|
toTitle (head:tail) = Char.toUpper head : toLower tail
|
2022-04-19 10:50:02 +03:00
|
|
|
|
|
|
|
toLower :: String -> String
|
|
|
|
toLower = map Char.toLower
|