module Text.MultipartNames.Show (
showLowerCamel,
showLowerHyphenated,
showLowerUnderscored,
showUpperCamel,
showUpperHyphenated,
showUpperUnderscored
) where
import qualified Data.CaseInsensitive as CI
import Data.Char
import Data.List(intercalate)
import Text.MultipartNames.MultipartName
showLowerCamel :: MultipartName -> String
showLowerCamel nm = concat (lower (CI.original $ head ss)
: map (cap . CI.original) (tail ss))
where
ss = toSegments nm
showUpperCamel :: MultipartName -> String
showUpperCamel nm = concatMap (cap . CI.original) ss
where
ss = toSegments nm
showLowerHyphenated :: MultipartName -> String
showLowerHyphenated nm = intercalate "-" $ map (lower . CI.original) ss
where
ss = toSegments nm
showUpperHyphenated :: MultipartName -> String
showUpperHyphenated nm = intercalate "-" $ map (upper . CI.original) ss
where
ss = toSegments nm
showLowerUnderscored :: MultipartName -> String
showLowerUnderscored nm = intercalate "_" $ map (lower . CI.original) ss
where
ss = toSegments nm
showUpperUnderscored :: MultipartName -> String
showUpperUnderscored nm = intercalate "_" $ map (upper . CI.original) ss
where
ss = toSegments nm
lower, upper, cap :: String -> String
lower = map toLower
upper = map toUpper
cap s = toUpper (head s) : lower (tail s)