Skip to content

Commit

Permalink
Add basic strict splitOn implementation
Browse files Browse the repository at this point in the history
The implementation is based on a @ezyang code snippet from haskell#100.
  • Loading branch information
Equwece committed Aug 1, 2023
1 parent bb31ef1 commit dc1cd27
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Data/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ module Data.ByteString (

-- ** Search for arbitrary substrings
breakSubstring,
splitOn,

-- * Searching ByteStrings

Expand Down Expand Up @@ -1633,6 +1634,19 @@ breakSubstring pat =
w' = mask .&. ((w `shiftL` 8) .|. b)
{-# INLINE shift #-}

splitOn :: ByteString -> ByteString -> [ByteString]
splitOn pat = go
where
patLen = length pat
breaker = breakSubstring pat
go s = pre : remainder
where
(pre, post) = breaker s
remainder =
if null post
then []
else go (drop patLen post)

-- ---------------------------------------------------------------------
-- Zipping

Expand Down

0 comments on commit dc1cd27

Please sign in to comment.