From 18074d6acde6d642b8fb10b1b49153f717c75446 Mon Sep 17 00:00:00 2001 From: simonmar Date: Wed, 20 Aug 2003 15:06:23 +0000 Subject: [PATCH] [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. --- ghc/compiler/utils/Util.lhs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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} -- 1.7.10.4