| | 177 | |
| | 178 | -- duplicated for now, pending über-Haskell-fu |
| | 179 | |
| | 180 | rxSplit_n :: VRule -> String -> Int -> Eval [Val] |
| | 181 | rxSplit_n _ [] n = return [] |
| | 182 | rxSplit_n rx str n = do |
| | 183 | match <- str `doMatch` rx |
| | 184 | if or [ ( n == 1 ), ( not (matchOk match) ) ] then return [VStr str] else do |
| | 185 | if matchFrom match == matchTo match |
| | 186 | then do |
| | 187 | let (c:cs) = str |
| | 188 | rest <- rxSplit_n rx (cs) (n-1) |
| | 189 | return (VStr [c]:rest) |
| | 190 | else do |
| | 191 | let before = genericTake (matchFrom match) str |
| | 192 | after = genericDrop (matchTo match) str |
| | 193 | rest <- rxSplit_n rx after (n-1) |
| | 194 | return $ (VStr before:matchSubPos match) ++ rest |