packages feed

utf8-env (empty) → 0.1

raw patch · 4 files changed

+154/−0 lines, 4 filesdep +basedep +mtldep +utf8-stringsetup-changed

Dependencies added: base, mtl, utf8-string

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Dmitry Golubovsky 2008.+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Dmitry Golubovsky nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ System/Environment/UTF8.hs view
@@ -0,0 +1,98 @@+-----------------------------------------------------------------------------+-- |+-- Module      :  System.Environment.UTF8+-- Copyright   :  (c) Dmitry Golubovsky, 2009+-- License     :  BSD-style (see the file libraries/base/LICENSE)+-- +-- Maintainer  :  golubovsky@gmail.com+-- Stability   :  experimental+-- Portability :  GHC, Unix+--+-- Miscellaneous information about the system environment, assuming it was+-- encoded in UTF-8. To be used as a drop-in replacement for System.Environment+--+-----------------------------------------------------------------------------+ +-- Portions of code suggested by Austin Seipp, +-- http://haskell.org/pipermail/haskell-cafe/2009-March/057511.html+-- Haddock comments are borrowed from the original System.Environment module.++module System.Environment.UTF8+    (+      getArgs,       -- :: IO [String]+      getProgName,   -- :: IO String+      getEnv,        -- :: String -> IO String+      withArgs,+      withProgName,+      getEnvironment+  ) where++import Codec.Binary.UTF8.String+import qualified System.Environment as E+import Control.Monad++-- | Computation 'getArgs' returns a list of the program's command+-- line arguments (not including the program name).++getArgs :: IO [String]++getArgs = E.getArgs >>= mapM (return . decodeString)++{-|+ Computation 'getProgName' returns the name of the program as it was+ invoked.+ + However, this is hard-to-impossible to implement on some non-Unix+ OSes, so instead, for maximum portability, we just return the leafname+ of the program as invoked. Even then there are some differences+ between platforms: on Windows, for example, a program invoked as foo+ is probably really @FOO.EXE@, and that is what 'getProgName' will return.+-}++getProgName :: IO String++getProgName = E.getProgName >>= return . decodeString++-- | Computation 'getEnv' @var@ returns the value+-- of the environment variable @var@.  +--+-- This computation may fail with:+--+--  * 'System.IO.Error.isDoesNotExistError' if the environment variable+--    does not exist.++getEnv :: String -> IO String++getEnv name = E.getEnv (encodeString name) >>= return . decodeString++{-|+ 'withArgs' @args act@ - while executing action @act@, have 'getArgs'+ return @args@.+-}++withArgs :: [String] -> IO a -> IO a+withArgs xs act = E.withArgs (map encodeString xs) act++{-|+ 'withProgName' @name act@ - while executing action @act@,+ have 'getProgName' return @name@.+-}++withProgName :: String -> IO a -> IO a+withProgName nm act = E.withProgName (encodeString nm) act++-- |'getEnvironment' retrieves the entire environment as a+-- list of @(key,value)@ pairs.+--+-- If an environment entry does not contain an @\'=\'@ character,+-- the @key@ is the whole entry and the @value@ is the empty string.++getEnvironment :: IO [(String, String)]++getEnvironment = do+  env <- E.getEnvironment+  let ks = map (decodeString . fst) env+      vs = map (decodeString . snd) env+  return $ zip ks vs++
+ utf8-env.cabal view
@@ -0,0 +1,24 @@+Name:           utf8-env+Version:        0.1+Author:         Dmitry Golubovsky+Maintainer:     Dmitry Golubovsky <golubovsky@gmail.com>+License:        BSD3+License-File:   LICENSE+Stability:      Experimental+Category:       System++Synopsis:       UTF-8 aware substitutes for functions in System.Environment+Description:    UTF-8 aware substitutes for functions in System.Environment+                It was tested with GHC 6.10.1 in Unix (Linux) environment.+                Hugs users do not need this package.+                Import System.Environment.UTF8 into your program, and+                use functions like getArgs and getEnv in usual way.+                UTF8-aware locale is expected, that is, environment+                has setting of LANG = en_US.utf8 or similar.+                +Build-Type:     Simple+Build-Depends:  base > 3, mtl, utf8-string++Exposed-Modules: System.Environment.UTF8++