-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Functions for working with strings, including Text, ByteString, etc. -- -- Functions for working with strings, including Text, ByteString, etc. @package strings @version 1.0.0 -- | Functions for working with strings, including Text, -- ByteString, etc. -- -- This module aims at offering a consistent interface across all the -- available string types. It currently offers instances for the ordinary -- Haskell String type, Text, lazy Text, -- ByteString, and lazy ByteString. -- -- If especially provides functions for some types, which are otherwise -- not available nativly (such as breakOnSubstring is not -- available for the lazy Text type, is offered by sBreak -- and strBreak). module Data.Strings -- | Create a Text object form an ordinary Haskell String. text :: String -> Text -- | Create a lazy Text object from an ordinary Haskell -- String. lazyText :: String -> Text -- | Create a ByteString object form an ordinary Haskell -- String. This function will encode a String using the UTF-8 -- character encoding. bytes :: String -> ByteString -- | Create a lazy ByteString object from an ordinary Haskell -- String. This function will encode a String using the UTF-8 -- character encoding. lazyBytes :: String -> ByteString -- | The Str class provides functions for working with arbitrary -- Strings. It is basically the same interface as provided by the -- Strings class. However, every input string is a Haskell String -- here, thus easing the usage of different string types with native -- Haskell String literals. -- -- For example strAppend suffix works with any string -- type for which an instance of Str is defined. In order to -- maximize the ease of use of this library, the functions are prefixed -- with str. -- -- The complexity and efficiency of these functions depends on the -- underlying string type being used. class (Eq a, Strings a) => Str a where strNull = sNull strLen = sLen strHead = sHead strLast = sLast strInit = sInit strTail = sTail strTake = sTake strDrop = sDrop strReplace n r = sReplace (fromString n) (fromString r) strBreak n = sBreak (fromString n) strSplit d s = (a, b) where (a, b, _) = sSplit (fromString d) s strSplitAll n = sSplitAll (fromString n) strConcat = sConcat strJoin d = let d' = fromUnicodeString d in strConcat . intersperse d' strAppend x xs = sConcat [xs, fromString x] strTrim = sTrim strPadLeft = sPadLeft strPadRight = sPadRight strPadBoth = sPadBoth strReverse = sReverse strStartsWith s pref = sStartsWith s (fromString pref) strEndsWith s suff = sEndsWith s (fromString suff) strEq s1 s2 = fromUnicodeString s1 == s2 fromString = sFromString fromUnicodeString = sFromUnicodeString toString = sToString toWord8 = sToWord8 strNull :: Str a => a -> Bool strLen :: Str a => a -> Int strHead :: Str a => a -> Char strLast :: Str a => a -> Char strInit :: Str a => a -> a strTail :: Str a => a -> a strTake :: Str a => Int -> a -> a strDrop :: Str a => Int -> a -> a strReplace :: Str a => String -> String -> a -> a strBreak :: Str a => String -> a -> (a, a) strSplit :: Str a => String -> a -> (a, a) strSplitAll :: Str a => String -> a -> [a] strConcat :: Str a => [a] -> a strJoin :: Str a => String -> [a] -> a strAppend :: Str a => String -> a -> a strTrim :: Str a => a -> a strPadLeft :: Str a => Char -> Int -> a -> a strPadRight :: Str a => Char -> Int -> a -> a strPadBoth :: Str a => Char -> Int -> a -> a strReverse :: Str a => a -> a strEq :: Str a => String -> a -> Bool strStartsWith :: Str a => a -> String -> Bool strEndsWith :: Str a => a -> String -> Bool fromString :: Str a => String -> a fromUnicodeString :: Str a => String -> a toString :: Str a => a -> String toWord8 :: Str a => a -> [Word8] -- | The goal of this class is to offer the same interface for various -- types of strings (ByteString, Text, Haskell -- String, etc.). If a certain type offers a native implementation -- for a given function, Strings uses it. If not, a default -- implementation is given. -- -- All of these functions are prefixed with s to avoid -- nameclashes with existing functions from the prelude. -- -- The complexity and efficiency of these functions depends on the -- underlying string type being used. class Strings a where sBreak d src = search 0 src where search a b | a `seq` b `seq` False = undefined search n s | sNull s = (src, sEmpty) | sStartsWith s d = (sTake n src, s) | otherwise = search (n + 1) (sTail s) sReplace n r = sConcat . replace n r where replace n r h = if sNull b then (if c then [a, r] else [a]) else a : r : replace n r b where (a, b, c) = sSplit n h sSplit d s = (a, sDrop (sLen d) b, not $ sNull b) where (a, b) = sBreak d s sSplitAll d s = if sNull b then (if c then [a, b] else [a]) else a : sSplitAll d b where (a, b, c) = sSplit d s sPadLeft c n s = let len = sLen s padLen = max 0 (n - len) padStr = sFromString $ replicate padLen c in sConcat [padStr, s] sPadRight c n s = let len = sLen s padLen = max 0 (n - len) padStr = sFromString $ replicate padLen c in sConcat [s, padStr] sPadBoth c n s = let len = sLen s padLen = (max 0 (n - len)) padLenR = padLen `quot` 2 padLenL = padLen - padLenR padStrL = sFromString $ replicate padLenL c padStrR = sFromString $ replicate padLenR c in sConcat [padStrL, s, padStrR] sNull :: Strings a => a -> Bool sEmpty :: Strings a => a sLen :: Strings a => a -> Int sHead :: Strings a => a -> Char sLast :: Strings a => a -> Char sInit :: Strings a => a -> a sTail :: Strings a => a -> a sTake :: Strings a => Int -> a -> a sDrop :: Strings a => Int -> a -> a sTakeWhile :: Strings a => (Char -> Bool) -> a -> a sDropWhile :: Strings a => (Char -> Bool) -> a -> a sReplace :: Strings a => a -> a -> a -> a sBreak :: Strings a => a -> a -> (a, a) sSplit :: Strings a => a -> a -> (a, a, Bool) sSplitAll :: Strings a => a -> a -> [a] sStartsWith :: Strings a => a -> a -> Bool sEndsWith :: Strings a => a -> a -> Bool sConcat :: Strings a => [a] -> a sTrim :: Strings a => a -> a sPadLeft :: Strings a => Char -> Int -> a -> a sPadRight :: Strings a => Char -> Int -> a -> a sPadBoth :: Strings a => Char -> Int -> a -> a sReverse :: Strings a => a -> a sFromString :: Strings a => String -> a sFromUnicodeString :: Strings a => String -> a sToString :: Strings a => a -> String sToWord8 :: Strings a => a -> [Word8] instance Chars Integer instance Chars Int64 instance Chars Int32 instance Chars Int16 instance Chars Int8 instance Chars Word64 instance Chars Word32 instance Chars Word16 instance Chars Word8 instance Chars Int instance Strings String instance Strings Text instance Strings Text instance Strings ByteString instance Strings ByteString instance Str String instance Str ByteString instance Str ByteString instance Str Text instance Str Text