{-
Copyright (C) 2010 John MacFarlane <jgm@berkeley.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}{- |
Module : Text.Pandoc.UTF8
Copyright : Copyright (C) 2010 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
Stability : alpha
Portability : portable
UTF-8 aware string IO functions that will work with GHC 6.10, 6.12, or 7.
-}moduleText.Pandoc.UTF8(readFile,writeFile,getContents,putStr,putStrLn,hPutStr,hPutStrLn,hGetContents,toString,fromString,toStringLazy,fromStringLazy,encodePath,decodeArg)whereimportSystem.IOhiding(readFile,writeFile,getContents,putStr,putStrLn,hPutStr,hPutStrLn,hGetContents)importPreludehiding(readFile,writeFile,getContents,putStr,putStrLn,catch)importqualifiedSystem.IOasIOimportqualifiedData.ByteString.Char8asBimportqualifiedData.ByteString.LazyasBLimportqualifiedData.Text.EncodingasTimportqualifiedData.TextasTimportqualifiedData.Text.LazyasTLimportqualifiedData.Text.Lazy.EncodingasTLreadFile::FilePath->IOStringreadFilef=doh<-openFile(encodePathf)ReadModehGetContentshwriteFile::FilePath->String->IO()writeFilefs=withFile(encodePathf)WriteMode$\h->hPutStrhsgetContents::IOStringgetContents=hGetContentsstdinputStr::String->IO()putStrs=hPutStrstdoutsputStrLn::String->IO()putStrLns=hPutStrLnstdoutshPutStr::Handle->String->IO()hPutStrhs=hSetEncodinghutf8>>IO.hPutStrhshPutStrLn::Handle->String->IO()hPutStrLnhs=hSetEncodinghutf8>>IO.hPutStrLnhshGetContents::Handle->IOStringhGetContents=fmaptoStringLazy.BL.hGetContents-- hGetContents h = hSetEncoding h utf8_bom-- >> hSetNewlineMode h universalNewlineMode-- >> IO.hGetContents h-- | Convert UTF8-encoded ByteString to String, also-- removing '\r' characters.toString::B.ByteString->StringtoString=filter(/='\r').T.unpack.T.decodeUtf8fromString::String->B.ByteStringfromString=T.encodeUtf8.T.pack-- | Convert UTF8-encoded ByteString to String, also-- removing '\r' characters.toStringLazy::BL.ByteString->StringtoStringLazy=filter(/='\r').TL.unpack.TL.decodeUtf8fromStringLazy::String->BL.ByteStringfromStringLazy=TL.encodeUtf8.TL.packencodePath::FilePath->FilePathdecodeArg::String->String#if MIN_VERSION_base(4,4,0)encodePath=iddecodeArg=id#elseencodePath=B.unpack.fromStringdecodeArg=toString.B.pack#endif