aboutsummaryrefslogtreecommitdiff
path: root/Utility/Misc.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-10-16 00:31:25 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-10-16 00:50:12 -0400
commit23f2a12816e250f6780f80443ef6ec31c13fca9e (patch)
tree98de024aa2909caa39f82a76ccde182afef5093b /Utility/Misc.hs
parent91366c896d9c9cb4519b451a64ed4d1e0ff52cb3 (diff)
broke up Utility
Diffstat (limited to 'Utility/Misc.hs')
-rw-r--r--Utility/Misc.hs29
1 files changed, 29 insertions, 0 deletions
diff --git a/Utility/Misc.hs b/Utility/Misc.hs
new file mode 100644
index 000000000..bc1834774
--- /dev/null
+++ b/Utility/Misc.hs
@@ -0,0 +1,29 @@
+{- misc utility functions
+ -
+ - Copyright 2010-2011 Joey Hess <joey@kitenet.net>
+ -
+ - Licensed under the GNU GPL version 3 or higher.
+ -}
+
+module Utility.Misc where
+
+import System.IO
+
+{- A version of hgetContents that is not lazy. Ensures file is
+ - all read before it gets closed. -}
+hGetContentsStrict :: Handle -> IO String
+hGetContentsStrict h = hGetContents h >>= \s -> length s `seq` return s
+
+{- A version of readFile that is not lazy. -}
+readFileStrict :: FilePath -> IO String
+readFileStrict f = readFile f >>= \s -> length s `seq` return s
+
+{- Attempts to read a value from a String. -}
+readMaybe :: (Read a) => String -> Maybe a
+readMaybe s = case reads s of
+ ((x,_):_) -> Just x
+ _ -> Nothing
+
+{- Catches IO errors and returns a Bool -}
+catchBool :: IO Bool -> IO Bool
+catchBool = flip catch (const $ return False)