import Panic
import SrcLoc
+import Data.List
+
data Flag m = Flag
{
flagName :: String, -- flag, without the leading -
= 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
import Control.Monad ( when )
import Data.Char
-import Data.List ( intersperse )
+import Data.List
import System.FilePath
import System.IO ( stderr, hPutChar )
-- 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
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
-- (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
import UniqFM
import DynFlags
import Ctype
-import Util ( maybePrefixMatch, readRational )
+import Util ( readRational )
import Control.Monad
import Data.Bits
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
-- * Comparisons
isEqual, eqListBy,
- thenCmp, cmpList, maybePrefixMatch,
+ thenCmp, cmpList,
removeSpaces,
-- * Transitive closures
\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}