@@ -111,6 +111,7 @@ module Data.Text
111111
112112 -- ** Breaking into many substrings
113113 , split
114+ , splitChar
114115 , splitWith
115116 , breakSubstring
116117
@@ -770,20 +771,46 @@ tails t | null t = [empty]
770771-- | /O(n)/ Break a 'Text' into pieces separated by the 'Char'
771772-- argument, consuming the delimiter. I.e.
772773--
773−-- > split '\n' "a\nb\nd\ne" == ["a","b","d","e"]
774−-- > split 'a' "aXaXaXa" == ["","X","X","X",""]
775−-- > split 'x' "x" == ["",""]
774+-- > splitChar '\n' "a\nb\nd\ne" == ["a","b","d","e"]
775+-- > splitChar 'a' "aXaXaXa" == ["","X","X","X",""]
776+-- > splitChar 'x' "x" == ["",""]
776777--
777778-- and
778779--
779−-- > intercalate (singleton c) . split c == id
780−-- > split == splitWith . (==)
780+-- > intercalate (singleton c) . splitChar c == id
781+-- > splitChar == splitWith . (==)
781782--
782783-- As for all splitting functions in this library, this function does
783784-- not copy the substrings, it just constructs new 'Text's that are
784785-- slices of the original.
785−split :: Char -> Text -> [Text]
786−split c = splitWith (==c)
786+splitChar :: Char -> Text -> [Text]
787+splitChar c = splitWith (==c)
788+{-# INLINE splitChar #-}
789+
790+-- | /O(m)*O(n)/ Break a 'Text' into pieces separated by the 'Text'
791+-- argument, consuming the delimiter. I.e.
792+--
793+-- > split "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
794+-- > split "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""]
795+-- > split "x" "x" == ["",""]
796+--
797+-- and
798+--
799+-- > intercalate s . split s == id
800+--
801+-- As for all splitting functions in this library, this function does
802+-- not copy the substrings, it just constructs new 'Text's that are
803+-- slices of the original.
804+split :: Text -> Text -> [Text]
805+split pat = go
806+ where
807+ go src = search 0 src
808+ where
809+ search !n !s
810+ | null s = [src] -- not found
811+ | pat `isPrefixOf` s = take n src : go (drop l s)
812+ | otherwise = search (n+1) (unsafeTail s)
813+ l = length pat
787814{-# INLINE split #-}
788815
789816-- | /O(n)/ Splits a 'Text' into components delimited by separators,