module GHC.Settings.Utils where

import Prelude -- See Note [Why do we import Prelude here?]

import Data.Char (isSpace)

maybeRead :: Read a => String -> Maybe a
maybeRead :: forall a. Read a => String -> Maybe a
maybeRead String
str = case ReadS a
forall a. Read a => ReadS a
reads String
str of
  [(a
x, String
"")] -> a -> Maybe a
forall a. a -> Maybe a
Just a
x
  [(a, String)]
_ -> Maybe a
forall a. Maybe a
Nothing

maybeReadFuzzy :: Read a => String -> Maybe a
maybeReadFuzzy :: forall a. Read a => String -> Maybe a
maybeReadFuzzy String
str = case ReadS a
forall a. Read a => ReadS a
reads String
str of
  [(a
x, String
s)] | (Char -> Bool) -> String -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Char -> Bool
isSpace String
s -> a -> Maybe a
forall a. a -> Maybe a
Just a
x
  [(a, String)]
_ -> Maybe a
forall a. Maybe a
Nothing