{-# LANGUAGE NoImplicitPrelude #-} module StringUtils ( strip, lstrip, rstrip, replace, split, splitFirst, ) where import IHaskellPrelude import qualified Data.Text as T import Data.List.Split (splitOn) import qualified Data.List.Split as Split lstrip :: String -> String lstrip :: String -> String lstrip = forall a. (a -> Bool) -> [a] -> [a] dropWhile (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool `elem` (String " \t\r\n" :: String)) rstrip :: String -> String rstrip :: String -> String rstrip = forall a. [a] -> [a] reverse forall b c a. (b -> c) -> (a -> b) -> a -> c . String -> String lstrip forall b c a. (b -> c) -> (a -> b) -> a -> c . forall a. [a] -> [a] reverse strip :: String -> String strip :: String -> String strip = String -> String rstrip forall b c a. (b -> c) -> (a -> b) -> a -> c . String -> String lstrip replace :: String -> String -> String -> String replace :: String -> String -> String -> String replace String needle String replacement String haystack = Text -> String T.unpack forall a b. (a -> b) -> a -> b $ Text -> Text -> Text -> Text T.replace (String -> Text T.pack String needle) (String -> Text T.pack String replacement) (String -> Text T.pack String haystack) split :: String -> String -> [String] split :: String -> String -> [String] split = forall a. Eq a => [a] -> [a] -> [[a]] splitOn splitFirst :: String -> String -> [String] splitFirst :: String -> String -> [String] splitFirst String delim String str = let (String head:String _:[String] tail) = forall a. Splitter a -> [a] -> [[a]] Split.split (forall a. Eq a => [a] -> Splitter a Split.onSublist String delim) String str in [String head, forall (t :: * -> *) a. Foldable t => t [a] -> [a] concat [String] tail]