Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
MCSP.Data.String.Extra.Radix
Description
Radix operations on String
.
Synopsis
- stripPrefix :: Eq a => String a -> String a -> Maybe (String a)
- isPrefixOf :: Eq a => String a -> String a -> Bool
- commonPrefix :: Eq a => String a -> String a -> String a
- splitCommonPrefix :: Eq a => String a -> String a -> (String a, String a, String a)
- stripInfix :: Eq a => String a -> String a -> Maybe (String a, String a)
- isInfixOf :: Eq a => String a -> String a -> Bool
- stripSuffix :: Eq a => String a -> String a -> Maybe (String a)
- isSuffixOf :: Eq a => String a -> String a -> Bool
- suffixes :: String a -> [String a]
Prefix
isPrefixOf :: Eq a => String a -> String a -> Bool Source #
O(min(m,n)) Returns True
iff the first string is a prefix of the second.
>>>
"Hello" `isPrefixOf` "Hello World!"
True
>>>
"Hello" `isPrefixOf` "Wello Horld!"
False
commonPrefix :: Eq a => String a -> String a -> String a Source #
O(min(m,n)) The maximum common prefix of two strings.
>>>
commonPrefix "abc" "abd"
ab
>>>
commonPrefix "xyz" "xyz"
xyz
>>>
commonPrefix "def" "ghi"
splitCommonPrefix :: Eq a => String a -> String a -> (String a, String a, String a) Source #
O(min(m,n)) Returns the maximum common prefix of two strings and the remainder of each string.
Note that splitCommonPrefix a b
is equivalent to
let p = commonPrefix a b in (p, fromJust (splitPrefix p a), fromJust (splitPrefix p b))
, but
slightly more efficient and cannot fail.
>>>
splitCommonPrefix "abc" "abd"
(ab,c,d)
>>>
splitCommonPrefix "xyz" "xyz"
(xyz,,)
>>>
splitCommonPrefix "def" "ghi"
(,def,ghi)
Infix
stripInfix :: Eq a => String a -> String a -> Maybe (String a, String a) Source #
O(n m) Return the the string before (prefix) and after (suffix) the search string, or
Nothing
if the search string is not present.
A result of
means that
Just
(s1, s2) = stripInfix
s rs1
.++
r ++
s2 ==
s
>>>
stripInfix "el" "Hello"
Just (H,lo)
>>>
stripInfix "World!" "Hello"
Nothing
>>>
stripInfix "si" "mississipi"
Just (mis,ssipi)
>>>
stripInfix "chat" "hat"
Nothing
>>>
stripInfix "word" "word"
Just (,)
isInfixOf :: Eq a => String a -> String a -> Bool Source #
O(n m) Check if the first string is contained anywhere within the second string.
>>>
isInfixOf "Haskell" "I really like Haskell."
True
>>>
isInfixOf "Ial" "I really like Haskell."
False
Suffix
stripSuffix :: Eq a => String a -> String a -> Maybe (String a) Source #
O(min(m,n)) Returns the prefix of the second string if its suffix matches the first string.
Returns Nothing
if the string does not end with the suffix given, or Just
the string before
the suffix.
>>>
stripSuffix "bar" "foobar"
Just foo
>>>
stripSuffix "" "baz"
Just baz
>>>
stripSuffix "foo" "quux"
Nothing