module Text.MultipartNames.MultipartName(
MultipartName,
mkMultipartName,
mkMultipartNameFromWords,
isLegalSegment,
toSegments
) where
import Data.CaseInsensitive(CI)
import qualified Data.CaseInsensitive as CI
import Data.Char(isAscii, isLetter)
newtype MultipartName = MultipartName [CI String]
deriving (Eq, Ord, Show)
toSegments :: MultipartName -> [CI String]
toSegments (MultipartName ss) = ss
mkMultipartName :: [String] -> MultipartName
mkMultipartName ss
| null ss = error "mkMultipartName []: argument cannot be null"
| all isLegalSegment ss
= MultipartName $ map CI.mk ss
| otherwise = error msg
where
msg = "mkMultipartName " ++ show ss
++ ": all segments must start with a cased letter"
mkMultipartNameFromWords :: String -> MultipartName
mkMultipartNameFromWords = mkMultipartName . words
isLegalSegment :: String -> Bool
isLegalSegment seg = case seg of
[] -> False
c : _ -> isAscii c && isLetter c