From: simonmar Date: Wed, 20 Aug 2003 15:06:23 +0000 (+0000) Subject: [project @ 2003-08-20 15:06:23 by simonmar] X-Git-Tag: Approx_11550_changesets_converted~539 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;ds=sidebyside;h=18074d6acde6d642b8fb10b1b49153f717c75446;p=ghc-hetmet.git [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. --- diff --git a/ghc/compiler/utils/Util.lhs b/ghc/compiler/utils/Util.lhs index f335062..28880a2 100644 --- a/ghc/compiler/utils/Util.lhs +++ b/ghc/compiler/utils/Util.lhs @@ -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}