ref: e93531c5846754c93f37951ab52bb961e73817f9
parent: 53362c02342a4582377af1b586ac92f11c6a8d1c
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Sat Feb 10 13:35:54 EST 2024
Add mkTextEncoding
--- a/lib/System/IO.hs
+++ b/lib/System/IO.hs
@@ -19,12 +19,13 @@
hSerialize, hDeserialize, cprint,
writeSerialized, readSerialized,
- hSetEncoding, utf8,
+ mkTextEncoding, hSetEncoding, utf8,
unsafeInterleaveIO,
getTimeMilli,
openTmpFile,
+ withFile,
) where
import Prelude() -- do not import Prelude
import Primitives
@@ -291,6 +292,10 @@
utf8 :: TextEncoding
utf8 = UTF8
+mkTextEncoding :: String -> IO TextEncoding
+mkTextEncoding "UTF-8//ROUNDTRIP" = return UTF8
+mkTextEncoding _ = error "unknown text encoding"
+
-- Always in UTF8 mode
hSetEncoding :: Handle -> TextEncoding -> IO ()
hSetEncoding _ _ = return ()
@@ -313,3 +318,11 @@
free ctmp
h <- openFile tmp WriteMode
return (tmp, h)
+
+-- XXX needs bracket
+withFile :: forall r . FilePath -> IOMode -> (Handle -> IO r) -> IO r
+withFile fn md io = do
+ h <- openFile fn md
+ r <- io h
+ hClose h
+ return r
--
⑨