Commit 18074d6a authored by simonmar's avatar simonmar

[project @ 2003-08-20 15:06:23 by simonmar]

Define maybePrefixMatch, which is like prefixMatch but returns the
rest of the String after the match.
parent affe9213
......@@ -34,7 +34,7 @@ module Util (
-- comparisons
eqListBy, equalLength, compareLength,
thenCmp, cmpList, prefixMatch, suffixMatch,
thenCmp, cmpList, prefixMatch, suffixMatch, maybePrefixMatch,
-- strictness
foldl', seqList,
......@@ -732,6 +732,13 @@ prefixMatch _pat [] = False
prefixMatch (p:ps) (s:ss) | p == s = prefixMatch ps ss
| otherwise = False
maybePrefixMatch :: String -> String -> Maybe String
maybePrefixMatch [] rest = Just rest
maybePrefixMatch (_:_) [] = Nothing
maybePrefixMatch (p:pat) (r:rest)
| p == r = maybePrefixMatch pat rest
| otherwise = Nothing
suffixMatch :: Eq a => [a] -> [a] -> Bool
suffixMatch pat str = prefixMatch (reverse pat) (reverse str)
\end{code}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment