module Data.Strings
(
module Data.String
,module Data.Char
,lower
,upper
,trim
,ellipsize
,ellipsizeFromFront
,ordSuffix
,pad
,stringToMaybe
,ToString(..))
where
import Data.Char
import Data.String
lower :: String -> String
lower = map toLower
upper :: String -> String
upper = map toUpper
trim :: String -> String
trim = reverse . dropWhile isSpace . reverse . dropWhile isSpace
ellipsize :: Int -> String -> String
ellipsize n xs
| length xs > n = take n $ take (max 1 (n1)) xs ++ "…"
| otherwise = xs
ellipsizeFromFront :: Int -> String -> String
ellipsizeFromFront n xs =
if length xs > n
then "…" ++ reverse (take (n1) (reverse xs))
else xs
ordSuffix :: (Integral n) => n -> String
ordSuffix n
| tens > 3 && tens < 21 = "th"
| otherwise = case n `mod` 10 of
1 -> "st"; 2 -> "nd"; 3 -> "rd"; _ -> "th"
where tens = n `mod` 100
pad :: Int
-> String
-> String
-> String
pad n c xs = take (n length xs) (cycle c) ++ xs
stringToMaybe :: String -> Maybe String
stringToMaybe (trim -> "") = Nothing
stringToMaybe x = Just x
class ToString a where
toString :: a -> String
instance ToString String where
toString = id