@@ -111,6 +111,7 @@ module Data.Text
112 -- ** Breaking into many substrings
112 -- ** Breaking into many substrings
114 , splitWith
115 , splitWith
115 , breakSubstring
116 , breakSubstring
@@ -770,20 +771,46 @@ tails t | null t = [empty]
770-- | /O(n)/ Break a 'Text' into pieces separated by the 'Char'
771-- | /O(n)/ Break a 'Text' into pieces separated by the 'Char'
771-- argument, consuming the delimiter. I.e.
772-- argument, consuming the delimiter. I.e.
773−-- > split '\n' "a\nb\nd\ne" == ["a","b","d","e"]
774+-- > splitChar '\n' "a\nb\nd\ne" == ["a","b","d","e"]
774−-- > split 'a' "aXaXaXa" == ["","X","X","X",""]
775+-- > splitChar 'a' "aXaXaXa" == ["","X","X","X",""]
775−-- > split 'x' "x" == ["",""]
776+-- > splitChar 'x' "x" == ["",""]
779−-- > intercalate (singleton c) . split c == id
780+-- > intercalate (singleton c) . splitChar c == id
780−-- > split == splitWith . (==)
781+-- > splitChar == splitWith . (==)
782-- As for all splitting functions in this library, this function does
783-- As for all splitting functions in this library, this function does
783-- not copy the substrings, it just constructs new 'Text's that are
784-- not copy the substrings, it just constructs new 'Text's that are
784-- slices of the original.
785-- slices of the original.
785−split :: Char -> Text -> [Text]
786+splitChar :: Char -> Text -> [Text]
786−split c = splitWith (==c)
787+splitChar c = splitWith (==c)
788+{-# INLINE splitChar #-}
790+-- | /O(m)*O(n)/ Break a 'Text' into pieces separated by the 'Text'
791+-- argument, consuming the delimiter. I.e.
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" == ["",""]
799+-- > intercalate s . split s == id
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]
807+ go src = search 0 src
810+ | null s = [src] -- not found
811+ | pat `isPrefixOf` s = take n src : go (drop l s)
812+ | otherwise = search (n+1) (unsafeTail s)
787{-# INLINE split #-}
814{-# INLINE split #-}
789-- | /O(n)/ Splits a 'Text' into components delimited by separators,
816-- | /O(n)/ Splits a 'Text' into components delimited by separators,