24 lines
638 B
Haskell
24 lines
638 B
Haskell
|
module Parsing (
|
||
|
splitByString
|
||
|
) where
|
||
|
|
||
|
import Data.List (isPrefixOf)
|
||
|
|
||
|
splitByString :: String -> String -> [String]
|
||
|
splitByString _ "" = []
|
||
|
splitByString splitter string =
|
||
|
let (chunk, rest) = spanNextSplit string
|
||
|
in
|
||
|
chunk:(splitByString splitter rest)
|
||
|
where
|
||
|
spanNextSplit :: String -> (String, String)
|
||
|
spanNextSplit [] = ([], [])
|
||
|
spanNextSplit everything@(char:rest)
|
||
|
| splitter `isPrefixOf` rest =
|
||
|
([char], (drop ((length splitter) + 1) everything))
|
||
|
| otherwise =
|
||
|
let
|
||
|
(start, end) = spanNextSplit rest
|
||
|
in
|
||
|
(char:start, end)
|