Skip to content

Instantly share code, notes, and snippets.

@ryo1kato
Created September 4, 2014 23:11
Show Gist options
  • Save ryo1kato/5ddeb944eda843d7f052 to your computer and use it in GitHub Desktop.
Save ryo1kato/5ddeb944eda843d7f052 to your computer and use it in GitHub Desktop.
--
-- split bstr into 3 parts: before, on, and after first line with match
--
fgrep_line pat bstr =
if BS.null bstr
then (BS.empty, BS.empty, BS.empty)
else (head, BS.concat[left, right], rem)
where
(h, t) = breakOn pat bstr
left = BS.tail $ afterLast (pack "\n") h
(right, rem) = breakOn (pack "\n") t
head = dropLast (BS.length left + 1) h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment