@@ -135,10 +135,10 @@ module Data.Text.Lazy
135 , stripStart
135 , stripStart
136 , stripEnd
136 , stripEnd
137 , splitAt
137 , splitAt
143 , groupBy
143 , groupBy
@@ -146,8 +146,8 @@ module Data.Text.Lazy
147 -- ** Breaking into many substrings
147 -- ** Breaking into many substrings
148 -- $split
148 -- $split
151 , chunksOf
151 , chunksOf
152 -- , breakSubstring
152 -- , breakSubstring
@@ -169,8 +169,8 @@ module Data.Text.Lazy
169 -- * Searching
169 -- * Searching
172− , findBy
172+ , breakOnAll
173− , partitionBy
173+ , partition
175 -- , findSubstring
175 -- , findSubstring
@@ -630,7 +630,7 @@ replace :: Text -- ^ Text to search for
630 -> Text -- ^ Replacement text
630 -> Text -- ^ Replacement text
631 -> Text -- ^ Input text
631 -> Text -- ^ Input text
633−replace s d = intercalate d . split s
633+replace s d = intercalate d . splitOn s
634{-# INLINE replace #-}
634{-# INLINE replace #-}
636-- ----------------------------------------------------------------------------
636-- ----------------------------------------------------------------------------
@@ -1044,13 +1044,13 @@ splitAtWord x (Chunk c@(T.Text arr off len) cs)
1045-- Examples:
1045-- Examples:
1047−-- > break "::" "a::b::c" ==> ("a", "::b::c")
1047+-- > breakOn "::" "a::b::c" ==> ("a", "::b::c")
1048−-- > break "/" "foobar" ==> ("foobar", "")
1048+-- > breakOn "/" "foobar" ==> ("foobar", "")
1052-- > append prefix match == haystack
1052-- > append prefix match == haystack
1053−-- > where (prefix, match) = break needle haystack
1053+-- > where (prefix, match) = breakOn needle haystack
1055-- If you need to break a string by a substring repeatedly (e.g. you
1055-- If you need to break a string by a substring repeatedly (e.g. you
1056-- want to break on every instance of a substring), use 'find'
1056-- want to break on every instance of a substring), use 'find'
@@ -1061,25 +1061,25 @@ splitAtWord x (Chunk c@(T.Text arr off len) cs)
1062-- In (unlikely) bad cases, this function's time complexity degrades
1062-- In (unlikely) bad cases, this function's time complexity degrades
1063-- towards /O(n*m)/.
1063-- towards /O(n*m)/.
1064−break :: Text -> Text -> (Text, Text)
1064+breakOn :: Text -> Text -> (Text, Text)
1065−break pat src
1065+breakOn pat src
1066− | null pat = emptyError "break"
1066+ | null pat = emptyError "breakOn"
1067 | otherwise = case indices pat src of
1067 | otherwise = case indices pat src of
1068 [] -> (src, empty)
1068 [] -> (src, empty)
1069 (x:_) -> let h :*: t = splitAtWord x src
1069 (x:_) -> let h :*: t = splitAtWord x src
1070 in (h, t)
1070 in (h, t)
1072−-- | /O(n+m)/ Similar to 'break', but searches from the end of the string.
1072+-- | /O(n+m)/ Similar to 'breakOn', but searches from the end of the string.
1074-- The first element of the returned tuple is the prefix of @haystack@
1074-- The first element of the returned tuple is the prefix of @haystack@
1075-- up to and including the last match of @needle@. The second is the
1075-- up to and including the last match of @needle@. The second is the
1076-- remainder of @haystack@, following the match.
1076-- remainder of @haystack@, following the match.
1078−-- > breakEnd "::" "a::b::c" ==> ("a::b::", "c")
1078+-- > breakOnEnd "::" "a::b::c" ==> ("a::b::", "c")
1079−breakEnd :: Text -> Text -> (Text, Text)
1079+breakOnEnd :: Text -> Text -> (Text, Text)
1080−breakEnd pat src = let (a,b) = break (reverse pat) (reverse src)
1080+breakOnEnd pat src = let (a,b) = breakOn (reverse pat) (reverse src)
1081 in (reverse b, reverse a)
1081 in (reverse b, reverse a)
1082−{-# INLINE breakEnd #-}
1082+{-# INLINE breakOnEnd #-}
1084-- | /O(n+m)/ Find all non-overlapping instances of @needle@ in
1084-- | /O(n+m)/ Find all non-overlapping instances of @needle@ in
1085-- @haystack@. Each element of the returned list consists of a pair:
1085-- @haystack@. Each element of the returned list consists of a pair:
@@ -1090,9 +1090,9 @@ breakEnd pat src = let (a,b) = break (reverse pat) (reverse src)
1091-- Examples:
1091-- Examples:
1093−-- > find "::" ""
1093+-- > breakOnAll "::" ""
1094-- > ==> []
1094-- > ==> []
1095−-- > find "/" "a/b/c/"
1095+-- > breakOnAll "/" "a/b/c/"
1096-- > ==> [("a", "/b/c/"), ("a/b", "/c/"), ("a/b/c", "/")]
1096-- > ==> [("a", "/b/c/"), ("a/b", "/c/"), ("a/b/c", "/")]
1098-- This function is strict in its first argument, and lazy in its
1098-- This function is strict in its first argument, and lazy in its
@@ -1102,11 +1102,11 @@ breakEnd pat src = let (a,b) = break (reverse pat) (reverse src)
1102-- towards /O(n*m)/.
1102-- towards /O(n*m)/.
1104-- The @needle@ parameter may not be empty.
1104-- The @needle@ parameter may not be empty.
1105−find :: Text -- ^ @needle@ to search for
1105+breakOnAll :: Text -- ^ @needle@ to search for
1106− -> Text -- ^ @haystack@ in which to search
1106+ -> Text -- ^ @haystack@ in which to search
1107− -> [(Text, Text)]
1107+ -> [(Text, Text)]
1108−find pat src
1108+breakOnAll pat src
1109− | null pat = emptyError "find"
1109+ | null pat = emptyError "breakOnAll"
1110 | otherwise = go 0 empty src (indices pat src)
1110 | otherwise = go 0 empty src (indices pat src)
1112 go !n p s (x:xs) = let h :*: t = splitAtWord (x-n) s
1112 go !n p s (x:xs) = let h :*: t = splitAtWord (x-n) s
@@ -1114,10 +1114,10 @@ find pat src
1114 in (h',t) : go x h' t xs
1114 in (h',t) : go x h' t xs
1115 go _ _ _ _ = []
1115 go _ _ _ _ = []
1117−-- | /O(n)/ 'breakBy' is like 'spanBy', but the prefix returned is over
1117+-- | /O(n)/ 'break' is like 'span', but the prefix returned is over
1118-- elements that fail the predicate @p@.
1118-- elements that fail the predicate @p@.
1119−breakBy :: (Char -> Bool) -> Text -> (Text, Text)
1119+break :: (Char -> Bool) -> Text -> (Text, Text)
1120−breakBy p t0 = break' t0
1120+break p t0 = break' t0
1121 where break' Empty = (empty, empty)
1121 where break' Empty = (empty, empty)
1122 break' c@(Chunk t ts) =
1122 break' c@(Chunk t ts) =
1123 case T.findIndex p t of
1123 case T.findIndex p t of
@@ -1127,13 +1127,13 @@ breakBy p t0 = break' t0
1127 | otherwise -> let (a,b) = T.splitAt n t
1127 | otherwise -> let (a,b) = T.splitAt n t
1128 in (Chunk a Empty, Chunk b ts)
1128 in (Chunk a Empty, Chunk b ts)
1130−-- | /O(n)/ 'spanBy', applied to a predicate @p@ and text @t@, returns
1130+-- | /O(n)/ 'span', applied to a predicate @p@ and text @t@, returns
1131-- a pair whose first element is the longest prefix (possibly empty)
1131-- a pair whose first element is the longest prefix (possibly empty)
1132-- of @t@ of elements that satisfy @p@, and whose second is the
1132-- of @t@ of elements that satisfy @p@, and whose second is the
1133-- remainder of the list.
1133-- remainder of the list.
1134−spanBy :: (Char -> Bool) -> Text -> (Text, Text)
1134+span :: (Char -> Bool) -> Text -> (Text, Text)
1135−spanBy p = breakBy (not . p)
1135+span p = break (not . p)
1136−{-# INLINE spanBy #-}
1136+{-# INLINE span #-}
1138-- | The 'group' function takes a 'Text' and returns a list of 'Text's
1138-- | The 'group' function takes a 'Text' and returns a list of 'Text's
1139-- such that the concatenation of the result is equal to the argument.
1139-- such that the concatenation of the result is equal to the argument.
@@ -1152,7 +1152,7 @@ group = groupBy (==)
1152groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
1152groupBy :: (Char -> Char -> Bool) -> Text -> [Text]
1153groupBy _ Empty = []
1153groupBy _ Empty = []
1154groupBy eq (Chunk t ts) = cons x ys : groupBy eq zs
1154groupBy eq (Chunk t ts) = cons x ys : groupBy eq zs
1155− where (ys,zs) = spanBy (eq x) xs
1155+ where (ys,zs) = span (eq x) xs
1156 x = T.unsafeHead t
1156 x = T.unsafeHead t
1157 xs = chunk (T.unsafeTail t) ts
1157 xs = chunk (T.unsafeTail t) ts
@@ -1184,37 +1184,37 @@ tails ts@(Chunk t ts')
1185-- Examples:
1185-- Examples:
1187−-- > split "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
1187+-- > splitOn "\r\n" "a\r\nb\r\nd\r\ne" == ["a","b","d","e"]
1188−-- > split "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""]
1188+-- > splitOn "aaa" "aaaXaaaXaaaXaaa" == ["","X","X","X",""]
1189−-- > split "x" "x" == ["",""]
1189+-- > splitOn "x" "x" == ["",""]
1193−-- > intercalate s . split s == id
1193+-- > intercalate s . splitOn s == id
1194−-- > split (singleton c) == splitBy (==c)
1194+-- > splitOn (singleton c) == split (==c)
1196-- This function is strict in its first argument, and lazy in its
1196-- This function is strict in its first argument, and lazy in its
1197-- second.
1197-- second.
1199-- In (unlikely) bad cases, this function's time complexity degrades
1199-- In (unlikely) bad cases, this function's time complexity degrades
1200-- towards /O(n*m)/.
1200-- towards /O(n*m)/.
1201−split :: Text -- ^ Text to split on
1201+splitOn :: Text -- ^ Text to split on
1202− -> Text -- ^ Input text
1202+ -> Text -- ^ Input text
1203− -> [Text]
1203+ -> [Text]
1204−split pat src
1204+splitOn pat src
1205− | null pat = emptyError "split"
1205+ | null pat = emptyError "splitOn"
1206− | isSingleton pat = splitBy (== head pat) src
1206+ | isSingleton pat = split (== head pat) src
1207 | otherwise = go 0 (indices pat src) src
1207 | otherwise = go 0 (indices pat src) src
1209 go _ [] cs = [cs]
1209 go _ [] cs = [cs]
1210 go !i (x:xs) cs = let h :*: t = splitAtWord (x-i) cs
1210 go !i (x:xs) cs = let h :*: t = splitAtWord (x-i) cs
1211 in h : go (x+l) xs (dropWords l t)
1211 in h : go (x+l) xs (dropWords l t)
1212 l = foldlChunks (\a (T.Text _ _ b) -> a + fromIntegral b) 0 pat
1212 l = foldlChunks (\a (T.Text _ _ b) -> a + fromIntegral b) 0 pat
1213−{-# INLINE [1] split #-}
1213+{-# INLINE [1] splitOn #-}
1215{-# RULES
1215{-# RULES
1216−"LAZY TEXT split/singleton -> splitBy/==" [~1] forall c t.
1216+"LAZY TEXT splitOn/singleton -> split/==" [~1] forall c t.
1217− split (singleton c) t = splitBy (==c) t
1217+ splitOn (singleton c) t = split (==c) t
1220-- | /O(n)/ Splits a 'Text' into components delimited by separators,
1220-- | /O(n)/ Splits a 'Text' into components delimited by separators,
@@ -1222,16 +1222,16 @@ split pat src
1222-- resulting components do not contain the separators. Two adjacent
1222-- resulting components do not contain the separators. Two adjacent
1223-- separators result in an empty component in the output. eg.
1223-- separators result in an empty component in the output. eg.
1225−-- > splitBy (=='a') "aabbaca" == ["","","bb","c",""]
1225+-- > split (=='a') "aabbaca" == ["","","bb","c",""]
1226−-- > splitBy (=='a') [] == [""]
1226+-- > split (=='a') [] == [""]
1227−splitBy :: (Char -> Bool) -> Text -> [Text]
1227+split :: (Char -> Bool) -> Text -> [Text]
1228−splitBy _ Empty = [Empty]
1228+split _ Empty = [Empty]
1229−splitBy p (Chunk t0 ts0) = comb [] (T.splitBy p t0) ts0
1229+split p (Chunk t0 ts0) = comb [] (T.split p t0) ts0
1230 where comb acc (s:[]) Empty = revChunks (s:acc) : []
1230 where comb acc (s:[]) Empty = revChunks (s:acc) : []
1231− comb acc (s:[]) (Chunk t ts) = comb (s:acc) (T.splitBy p t) ts
1231+ comb acc (s:[]) (Chunk t ts) = comb (s:acc) (T.split p t) ts
1232 comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
1232 comb acc (s:ss) ts = revChunks (s:acc) : comb [] ss ts
1233− comb _ [] _ = impossibleError "splitBy"
1233+ comb _ [] _ = impossibleError "split"
1234−{-# INLINE splitBy #-}
1234+{-# INLINE split #-}
1236-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
1236-- | /O(n)/ Splits a 'Text' into components of length @k@. The last
1237-- element may be shorter than the other chunks, depending on the
1237-- element may be shorter than the other chunks, depending on the
@@ -1251,14 +1251,14 @@ chunksOf k = go
1251-- newline 'Char's. The resulting strings do not contain newlines.
1251-- newline 'Char's. The resulting strings do not contain newlines.
1252lines :: Text -> [Text]
1252lines :: Text -> [Text]
1253lines Empty = []
1253lines Empty = []
1254−lines t = let (l,t') = breakBy ((==) '\n') t
1254+lines t = let (l,t') = break ((==) '\n') t
1255 in l : if null t' then []
1255 in l : if null t' then []
1256 else lines (tail t')
1256 else lines (tail t')
1258-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
1258-- | /O(n)/ Breaks a 'Text' up into a list of words, delimited by 'Char's
1259-- representing white space.
1259-- representing white space.
1260words :: Text -> [Text]
1260words :: Text -> [Text]
1261−words = L.filter (not . null) . splitBy isSpace
1261+words = L.filter (not . null) . split isSpace
1262{-# INLINE words #-}
1262{-# INLINE words #-}
1264-- | /O(n)/ Joins lines, after appending a terminating newline to
1264-- | /O(n)/ Joins lines, after appending a terminating newline to
@@ -1378,21 +1378,21 @@ filter :: (Char -> Bool) -> Text -> Text
1378filter p t = unstream (S.filter p (stream t))
1378filter p t = unstream (S.filter p (stream t))
1379{-# INLINE filter #-}
1379{-# INLINE filter #-}
1381−-- | /O(n)/ The 'findBy' function takes a predicate and a 'Text', and
1381+-- | /O(n)/ The 'find' function takes a predicate and a 'Text', and
1382-- returns the first element in matching the predicate, or 'Nothing'
1382-- returns the first element in matching the predicate, or 'Nothing'
1383-- if there is no such element.
1383-- if there is no such element.
1384−findBy :: (Char -> Bool) -> Text -> Maybe Char
1384+find :: (Char -> Bool) -> Text -> Maybe Char
1385−findBy p t = S.findBy p (stream t)
1385+find p t = S.findBy p (stream t)
1386−{-# INLINE findBy #-}
1386+{-# INLINE find #-}
1388−-- | /O(n)/ The 'partitionBy' function takes a predicate and a 'Text',
1388+-- | /O(n)/ The 'partition' function takes a predicate and a 'Text',
1389-- and returns the pair of 'Text's with elements which do and do not
1389-- and returns the pair of 'Text's with elements which do and do not
1390-- satisfy the predicate, respectively; i.e.
1390-- satisfy the predicate, respectively; i.e.
1392−-- > partitionBy p t == (filter p t, filter (not . p) t)
1392+-- > partition p t == (filter p t, filter (not . p) t)
1393−partitionBy :: (Char -> Bool) -> Text -> (Text, Text)
1393+partition :: (Char -> Bool) -> Text -> (Text, Text)
1394−partitionBy p t = (filter p t, filter (not . p) t)
1394+partition p t = (filter p t, filter (not . p) t)
1395−{-# INLINE partitionBy #-}
1395+{-# INLINE partition #-}
1397-- | /O(n)/ 'Text' index (subscript) operator, starting from 0.
1397-- | /O(n)/ 'Text' index (subscript) operator, starting from 0.
1398index :: Text -> Int64 -> Char
1398index :: Text -> Int64 -> Char