rename readMaybe to readish

a stricter (but also partial) readMaybe is getting added to base
This commit is contained in:
Joey Hess 2012-01-23 17:00:10 -04:00
parent 5e172b43c4
commit ba6088b249
9 changed files with 13 additions and 13 deletions

View file

@ -101,7 +101,7 @@ hostport2socket host (Just port) = host ++ "!" ++ show port
socket2hostport :: FilePath -> (String, Maybe Integer)
socket2hostport socket
| null p = (h, Nothing)
| otherwise = (h, readMaybe p)
| otherwise = (h, readish p)
where
(h, p) = separate (== '!') $ takeFileName socket

View file

@ -40,7 +40,7 @@ remoteConfig r key = "remote." ++ fromMaybe "" (Git.remoteName r) ++ ".annex-" +
remoteCost :: Git.Repo -> Int -> Annex Int
remoteCost r def = do
cmd <- getConfig r "cost-command" ""
(fromMaybe def . readMaybe) <$>
(fromMaybe def . readish) <$>
if not $ null cmd
then liftIO $ snd <$> pipeFrom "sh" ["-c", cmd]
else getConfig r "cost" ""
@ -78,7 +78,7 @@ getNumCopies v = perhaps (use v) =<< Annex.getState Annex.forcenumcopies
where
use (Just n) = return n
use Nothing = perhaps (return 1) =<<
readMaybe <$> fromRepo (Git.Config.get config "1")
readish <$> fromRepo (Git.Config.get config "1")
perhaps fallback = maybe fallback (return . id)
config = "annex.numcopies"

View file

@ -45,7 +45,7 @@ port :: Repo -> Maybe Integer
port r =
case authpart uriPort r of
":" -> Nothing
(':':p) -> readMaybe p
(':':p) -> readish p
_ -> Nothing
{- Hostname of an URL repo, including any username (ie, "user@host") -}

View file

@ -119,7 +119,7 @@ options = Option.common ++
"skip files not using a key-value backend"
] ++ Option.matcher
where
setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readMaybe v }
setnumcopies v = Annex.changeState $ \s -> s {Annex.forcenumcopies = readish v }
setgitconfig :: String -> Annex ()
setgitconfig v = do
newg <- inRepo $ Git.Config.store v

View file

@ -84,7 +84,7 @@ addIn name = addLimit $ check $ if name == "." then inAnnex else inremote
- of copies. -}
addCopies :: String -> Annex ()
addCopies num =
case readMaybe num :: Maybe Int of
case readish num :: Maybe Int of
Nothing -> error "bad number for --copies"
Just n -> addLimit $ check n
where

View file

@ -36,7 +36,7 @@ withAttrFilesInGit attr a params = do
withNumCopies :: (Maybe Int -> FilePath -> CommandStart) -> CommandSeek
withNumCopies a params = withAttrFilesInGit "annex.numcopies" go params
where
go (file, v) = a (readMaybe v) file
go (file, v) = a (readish v) file
withBackendFilesInGit :: (BackendFile -> CommandStart) -> CommandSeek
withBackendFilesInGit a params =

View file

@ -69,8 +69,8 @@ readKey s = if key == Just stubKey then Nothing else key
findfields _ v = v
addbackend k v = Just k { keyBackendName = v }
addfield 's' k v = Just k { keySize = readMaybe v }
addfield 'm' k v = Just k { keyMtime = readMaybe v }
addfield 's' k v = Just k { keySize = readish v }
addfield 'm' k v = Just k { keyMtime = readish v }
addfield _ _ _ = Nothing
prop_idempotent_key_read_show :: Key -> Bool

View file

@ -88,7 +88,7 @@ gen = filter (not . empty) . fuse [] . scan [] . decode_c
| c == '}' = foundvar f var (readjustify $ reverse p) cs
| otherwise = inpad (c:p) f var cs
inpad p f var [] = Const (novar $ p++";"++var) : f
readjustify = getjustify . fromMaybe 0 . readMaybe
readjustify = getjustify . fromMaybe 0 . readish
getjustify i
| i == 0 = UnJustified
| i < 0 = LeftJustified (-1 * i)

View file

@ -10,7 +10,7 @@ module Utility.PartialPrelude where
import qualified Data.Maybe
{- read should be avoided, as it throws an error
- Instead, use: readMaybe -}
- Instead, use: readish -}
read :: Read a => String -> a
read = Prelude.read
@ -42,8 +42,8 @@ last = Prelude.last
- readMaybe is available in Text.Read in new versions of GHC,
- but that one requires the entire string to be consumed.
-}
readMaybe :: Read a => String -> Maybe a
readMaybe s = case reads s of
readish :: Read a => String -> Maybe a
readish s = case reads s of
((x,_):_) -> Just x
_ -> Nothing