Skip to content

Instantly share code, notes, and snippets.

@drchaos
Created July 31, 2023 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drchaos/1d27e31685f476ce7894daa035f522c3 to your computer and use it in GitHub Desktop.
Save drchaos/1d27e31685f476ce7894daa035f522c3 to your computer and use it in GitHub Desktop.
Glob-like pattern Boyer-Moore
-- Эта функция очень похожа на предыдущую. Она находит первое
-- вхожение подстроки и возвращает остаток
strip :: ByteString -> ByteString -> Maybe ByteString
strip pat
| null pat = Just
strip pat = breaker
where
!patLen = length pat
searcher = nonOverlappingIndices pat
breaker str = case searcher str of
[] -> Nothing
(i:_) -> Just $ snd $ splitAt (i + patLen) str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment