module Summoner.Text
( endLine
, packageToModule
, packageNameValid
, moduleNameValid
, intercalateMap
, headToUpper
, tconcatMap
) where
import qualified Data.Char as C
import qualified Data.Text as T
endLine :: Text
endLine = "\n"
packageToModule :: Text -> Text
packageToModule = tconcatMap headToUpper . T.splitOn "-"
packageNameValid :: Text -> Bool
packageNameValid = T.all (\c -> c == '-' || C.isAlphaNum c)
moduleNameValid :: Text -> Bool
moduleNameValid = all isValidFragment . T.split (== '.')
where
isValidFragment :: Text -> Bool
isValidFragment s =
s /= ""
&& T.all C.isAlphaNum s
&& C.isUpper (T.head s)
intercalateMap :: Text -> (a -> Text) -> [a] -> Text
intercalateMap between showT = T.intercalate between . map showT
headToUpper :: Text -> Text
headToUpper t = case T.uncons t of
Nothing -> ""
Just (x, xs) -> T.cons (C.toUpper x) xs
tconcatMap :: (a -> Text) -> [a] -> Text
tconcatMap f = T.concat . map f