Commit 46bef1c0 authored by Ian Lynagh's avatar Ian Lynagh

Remove maybePrefixMatch, using stripPrefix instead

We already require GHC 6.8 to build, and that included stripPrefix
in Data.List.
parent 3e39f848
......@@ -23,6 +23,8 @@ import Outputable
import Panic
import SrcLoc
import Data.List
data Flag m = Flag
{
flagName :: String, -- flag, without the leading -
......@@ -118,7 +120,7 @@ findArg spec arg
= case [ (removeSpaces rest, optKind, flagDeprecated flag)
| flag <- spec,
let optKind = flagOptKind flag,
Just rest <- [maybePrefixMatch (flagName flag) arg],
Just rest <- [stripPrefix (flagName flag) arg],
arg_ok optKind rest arg ]
of
[] -> Nothing
......
......@@ -92,7 +92,7 @@ import Data.IORef
import Control.Monad ( when )
import Data.Char
import Data.List ( intersperse )
import Data.List
import System.FilePath
import System.IO ( stderr, hPutChar )
......@@ -826,7 +826,7 @@ addDepSuffix s d = d { depSuffixes = deOptDep s : depSuffixes d }
-- We used to use "-optdep-flag -optdeparg", so for legacy applications
-- we need to strip the "-optdep" off of the arg
deOptDep :: String -> String
deOptDep x = case maybePrefixMatch "-optdep" x of
deOptDep x = case stripPrefix "-optdep" x of
Just rest -> rest
Nothing -> x
......
......@@ -265,8 +265,8 @@ mungePackagePaths top_dir ps = map munge_pkg ps
munge_paths = map munge_path
munge_path p
| Just p' <- maybePrefixMatch "$topdir" p = top_dir ++ p'
| Just p' <- maybePrefixMatch "$httptopdir" p = toHttpPath top_dir ++ p'
| Just p' <- stripPrefix "$topdir" p = top_dir ++ p'
| Just p' <- stripPrefix "$httptopdir" p = toHttpPath top_dir ++ p'
| otherwise = p
toHttpPath p = "file:///" ++ p
......
......@@ -134,7 +134,7 @@ lookUp sw = sw `elem` packed_static_opts
-- (lookup_str "foo") looks for the flag -foo=X or -fooX,
-- and returns the string X
lookup_str sw
= case firstJust (map (maybePrefixMatch sw) staticFlags) of
= case firstJust (map (stripPrefix sw) staticFlags) of
Just ('=' : str) -> Just str
Just str -> Just str
Nothing -> Nothing
......
......@@ -65,7 +65,7 @@ import SrcLoc
import UniqFM
import DynFlags
import Ctype
import Util ( maybePrefixMatch, readRational )
import Util ( readRational )
import Control.Monad
import Data.Bits
......@@ -1323,7 +1323,7 @@ lex_escape = do
Just (c3,i3) ->
let str = [c1,c2,c3] in
case [ (c,rest) | (p,c) <- silly_escape_chars,
Just rest <- [maybePrefixMatch p str] ] of
Just rest <- [stripPrefix p str] ] of
(escape_char,[]):_ -> do
setInput i3
return escape_char
......
......@@ -42,7 +42,7 @@ module Util (
-- * Comparisons
isEqual, eqListBy,
thenCmp, cmpList, maybePrefixMatch,
thenCmp, cmpList,
removeSpaces,
-- * Transitive closures
......@@ -664,15 +664,6 @@ cmpList cmp (a:as) (b:bs)
\end{code}
\begin{code}
-- This (with a more general type) is Data.List.stripPrefix from GHC 6.8.
-- This definition can be removed once we require at least 6.8 to build.
maybePrefixMatch :: String -> String -> Maybe String
maybePrefixMatch [] rest = Just rest
maybePrefixMatch (_:_) [] = Nothing
maybePrefixMatch (p:pat) (r:rest)
| p == r = maybePrefixMatch pat rest
| otherwise = Nothing
removeSpaces :: String -> String
removeSpaces = reverse . dropWhile isSpace . reverse . dropWhile isSpace
\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