packages feed

utf8-string 0.3.8 → 1

raw patch · 5 files changed

+17/−194 lines, 5 filesdep ~base

Dependency ranges changed: base

Files

CHANGELOG.markdown view
@@ -1,3 +1,7 @@+1+-----+* Remove out all the old utf8 IO support. GHC supports utf8 now.+ 0.3.8 ----- * Performance tweaks
Codec/Binary/UTF8/String.hs view
@@ -7,7 +7,7 @@ -- Module      :  Codec.Binary.UTF8.String -- Copyright   :  (c) Eric Mertens 2007 -- License     :  BSD3-style (see LICENSE)--- +-- -- Maintainer:    emertens@galois.com -- Stability   :  experimental -- Portability :  portable@@ -21,7 +21,7 @@     , encodeString     , decodeString     , encodeChar-    +     , isUTF8Encoded     , utf8Encode   ) where@@ -122,7 +122,7 @@ -- | @isUTF8Encoded str@ tries to recognize input string as being in UTF-8 form. isUTF8Encoded :: String -> Bool isUTF8Encoded [] = True-isUTF8Encoded (x:xs) = +isUTF8Encoded (x:xs) =   case ox of     _ | ox < 0x80  -> isUTF8Encoded xs       | ox > 0xff  -> False@@ -135,14 +135,14 @@       | otherwise  -> False  where    ox = toW32 x-   +    toW32 :: Char -> Word32    toW32 ch = fromIntegral (fromEnum ch) -   check1 = +   check1 =     case xs of      [] -> False-     c1 : ds +     c1 : ds       | oc .&. 0xc0 /= 0x80 || d < 0x000080 -> False       | otherwise -> isUTF8Encoded ds       where@@ -153,15 +153,15 @@    check_byte i mask overlong = aux i xs (ox .&. mask)       where         aux 0 rs acc-         | overlong <= acc && -	   acc <= 0x10ffff &&+         | overlong <= acc &&+           acc <= 0x10ffff &&            (acc < 0xd800 || 0xdfff < acc) &&            (acc < 0xfffe || 0xffff < acc) = isUTF8Encoded rs          | otherwise = False          aux n (r:rs) acc-         | toW32 r .&. 0xc0 == 0x80 = -	    aux (n-1) rs  (acc `shiftL` 6 .|. (toW32 r .&. 0x3f))+         | toW32 r .&. 0xc0 == 0x80 =+            aux (n-1) rs  (acc `shiftL` 6 .|. (toW32 r .&. 0x3f))          aux _ _  _ = False 
− System/Environment/UTF8.hs
@@ -1,41 +0,0 @@-{-# LANGUAGE CPP #-}-#if __GLASGOW_HASKELL__ >= 701-{-# LANGUAGE Trustworthy #-}-#endif------ |--- Module      :  System.Environment.UTF8--- Copyright   :  (c) Eric Mertens 2009--- License     :  BSD3-style (see LICENSE)------ Maintainer:    emertens@galois.com--- Stability   :  experimental--- Portability :  portable------ Support for UTF-8 based environment manipulation----module System.Environment.UTF8-  (getArgs, getProgName, getEnv, withArgs, withProgName, getEnvironment)-  where--import Codec.Binary.UTF8.String (decodeString)-import qualified System.Environment as Sys--getArgs :: IO [String]-getArgs = map decodeString `fmap` Sys.getArgs--getProgName :: IO String-getProgName = decodeString `fmap` Sys.getProgName--getEnv :: String -> IO String-getEnv x = decodeString `fmap` Sys.getEnv x--withArgs :: [String] -> IO a -> IO a-withArgs = Sys.withArgs--withProgName :: String -> IO a -> IO a-withProgName = Sys.withProgName--getEnvironment :: IO [(String,String)]-getEnvironment = map f `fmap` Sys.getEnvironment-  where f (a,b) = (decodeString a, decodeString b)
− System/IO/UTF8.hs
@@ -1,130 +0,0 @@-{-# LANGUAGE CPP #-}-#if __GLASGOW_HASKELL__ >= 701-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------------------- |--- Module      :  System.IO.UTF8--- Copyright   :  (c) Eric Mertens 2007--- License     :  BSD3-style (see LICENSE)--- --- Maintainer:    emertens@galois.com--- Stability   :  experimental--- Portability :  portable------ String IO preserving UTF8 encoding.-----module System.IO.UTF8 (-      print-    , putStr-    , putStrLn-    , getLine-    , readLn-    , openBinaryFile-    , withBinaryFile-    , readFile-    , writeFile-    , appendFile-    , interact-    , getContents-    , hGetLine-    , hGetContents-    , hPutStr-    , hPutStrLn-  ) where--import Control.Monad (liftM)-import Data.Word (Word8)-import Prelude (String, (=<<), (.), map, Enum(toEnum, fromEnum), Read,-                Show(..))-import System.IO (Handle, IO, FilePath, IOMode(AppendMode, ReadMode, WriteMode))-import qualified System.IO as IO-import Control.Exception (bracket)--import Codec.Binary.UTF8.String (encode, decode)----- | Encode a string in UTF8 form.-encodeString :: String -> String-encodeString xs = bytesToString (encode xs)---- | Decode a string from UTF8-decodeString :: String -> String-decodeString xs = decode (stringToBytes xs)---- | Convert a list of bytes to a String-bytesToString :: [Word8] -> String-bytesToString xs = map (toEnum . fromEnum) xs---- | String to list of bytes.-stringToBytes :: String -> [Word8]-stringToBytes xs = map (toEnum . fromEnum) xs---- | The 'print' function outputs a value of any printable type to the--- standard output device. This function differs from the--- System.IO.print in that it preserves any UTF8 encoding of the shown value.----print :: Show a => a -> IO ()-print x = putStrLn (show x)---- | Write a UTF8 string to the standard output device-putStr :: String -> IO ()-putStr x = IO.putStr (encodeString x)---- | The same as 'putStr', but adds a newline character.-putStrLn :: String -> IO ()-putStrLn x = IO.putStrLn (encodeString x)---- | Read a UTF8 line from the standard input device-getLine :: IO String-getLine = liftM decodeString IO.getLine---- | The 'readLn' function combines 'getLine' and 'readIO', preserving UTF8-readLn :: Read a => IO a-readLn = IO.readIO =<< getLine--openBinaryFile :: FilePath -> IOMode -> IO Handle-openBinaryFile n m = IO.openBinaryFile (encodeString n) m--withBinaryFile :: FilePath -> IOMode -> (Handle -> IO a) -> IO a-withBinaryFile n m f = bracket (openBinaryFile n m) IO.hClose f---- | The 'readFile' function reads a file and--- returns the contents of the file as a UTF8 string.--- The file is read lazily, on demand, as with 'getContents'.-readFile :: FilePath -> IO String-readFile n = hGetContents =<< openBinaryFile n ReadMode---- | The computation 'writeFile' @file str@ function writes the UTF8 string @str@,--- to the file @file@.-writeFile :: FilePath -> String -> IO ()-writeFile n s = withBinaryFile n WriteMode (\ h -> hPutStr h s)---- | The computation 'appendFile' @file str@ function appends the UTF8 string @str@,--- to the file @file@.-appendFile :: FilePath -> String -> IO ()-appendFile n s = withBinaryFile n AppendMode (\ h -> hPutStr h s)---- | Read a UTF8 line from a Handle-hGetLine :: Handle -> IO String-hGetLine h = liftM decodeString (IO.hGetLine h)---- | Lazily read a UTF8 string from a Handle-hGetContents :: Handle -> IO String-hGetContents h = liftM decodeString (IO.hGetContents h)---- | Write a UTF8 string to a Handle.-hPutStr :: Handle -> String -> IO ()-hPutStr h s = IO.hPutStr h (encodeString s)---- | Write a UTF8 string to a Handle, appending a newline.-hPutStrLn :: Handle -> String -> IO ()-hPutStrLn h s = IO.hPutStrLn h (encodeString s)---- | Lazily read stdin as a UTF8 string.-getContents :: IO String-getContents = liftM decodeString IO.getContents--interact :: (String -> String) -> IO ()-interact f = IO.interact (encodeString . f . decodeString)
utf8-string.cabal view
@@ -1,12 +1,12 @@ Name:               utf8-string-Version:            0.3.8+Version:            1 Author:             Eric Mertens Maintainer:         emertens@galois.com License:            BSD3 License-file:       LICENSE Homepage:           http://github.com/glguy/utf8-string/ Synopsis:           Support for reading and writing UTF8 Strings-Description:        A UTF8 layer for IO and Strings. The utf8-string+Description:        A UTF8 layer for Strings. The utf8-string                     package provides operations for encoding UTF8                     strings to Word8 lists and back, and for reading and                     writing UTF8 without truncation.@@ -15,24 +15,14 @@ cabal-version:      >= 1.2 Extra-Source-Files: CHANGELOG.markdown --flag bytestring-in-base-  default: False- library   Ghc-options:        -W -O2 -  if flag(bytestring-in-base)-    build-depends: base >= 2.0 && < 2.2-    cpp-options: -DBYTESTRING_IN_BASE-  else-    build-depends: base >= 3 && < 4.8, bytestring >= 0.9+  build-depends: base >= 4.3 && < 4.9, bytestring >= 0.9    Extensions:         CPP   Exposed-modules:    Codec.Binary.UTF8.String                       Codec.Binary.UTF8.Generic-                      System.IO.UTF8-                      System.Environment.UTF8                       Data.String.UTF8                       Data.ByteString.UTF8                       Data.ByteString.Lazy.UTF8