setlocale 0.0.3 → 1.0.0
raw patch · 5 files changed
+88/−56 lines, 5 filesdep ~basesetup-changednew-uploader
Dependency ranges changed: base
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- Setup.lhs +0/−3
- System/Locale/SetLocale.hsc +32/−39
- setlocale.cabal +24/−14
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Sven Bartscher++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 Sven Bartscher 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
− Setup.lhs
@@ -1,3 +0,0 @@-#!/usr/bin/env runhaskell-> import Distribution.Simple-> main = defaultMain
System/Locale/SetLocale.hsc view
@@ -1,35 +1,32 @@-{-# LANGUAGE ForeignFunctionInterface #-}--module System.Locale.SetLocale (- Category(..),- categoryToCInt,- setLocale-) where+{-# LANGUAGE DeriveDataTypeable+ , ForeignFunctionInterface #-} -import Foreign.Ptr-import Foreign.C.Types-import Foreign.C.String+-- Copyright (c) 2014, Sven Bartscher+-- Look the file LICENSE.txt in the toplevel directory of the source tree for+-- more information. -import Data.Typeable+module System.Locale.SetLocale ( Category(..)+ , categoryToCInt+ , setLocale+ )+ where --- | A type representing the various locale categories. See @man 7 locale@.-data Category- = LC_ALL- | LC_COLLATE- | LC_CTYPE- | LC_MESSAGES- | LC_MONETARY- | LC_NUMERIC- | LC_TIME- deriving (Eq, Ord, Read, Show, Enum, Bounded)+#include <locale.h> -instance Typeable Category where- typeOf _ = mkTyConApp (mkTyCon "System.Locale.SetLocale.Category") []+import Data.Typeable+import Data.Maybe+import Foreign.C+import Foreign.Ptr -#include <locale.h>+data Category = LC_ALL+ | LC_COLLATE+ | LC_CTYPE+ | LC_MESSAGES+ | LC_MONETARY+ | LC_NUMERIC+ | LC_TIME+ deriving (Bounded, Enum, Eq, Ord, Read, Show, Typeable) --- | Convert a 'Category' to the corresponding system-specific @LC_*@ code.--- You probably don't need this function. categoryToCInt :: Category -> CInt categoryToCInt LC_ALL = #const LC_ALL categoryToCInt LC_COLLATE = #const LC_COLLATE@@ -39,18 +36,14 @@ categoryToCInt LC_NUMERIC = #const LC_NUMERIC categoryToCInt LC_TIME = #const LC_TIME -ptr2str :: Ptr CChar -> IO (Maybe String)-ptr2str p- | p == nullPtr = return Nothing- | otherwise = fmap Just $ peekCString p--str2ptr :: Maybe String -> (Ptr CChar -> IO a) -> IO a-str2ptr Nothing f = f nullPtr-str2ptr (Just s) f = withCString s f--foreign import ccall unsafe "locale.h setlocale" c_setlocale :: CInt -> Ptr CChar -> IO (Ptr CChar)+foreign import ccall "locale.h setlocale" c_setlocale :: CInt -> CString -> IO (CString) --- | A Haskell version of @setlocale()@. See @man 3 setlocale@. setLocale :: Category -> Maybe String -> IO (Maybe String)-setLocale cat str =- str2ptr str $ \p -> c_setlocale (categoryToCInt cat) p >>= ptr2str+setLocale c Nothing = c_setlocale (categoryToCInt c) nullPtr >>= checkReturn+setLocale c (Just locale) = (withCString locale $ c_setlocale $ categoryToCInt c)+ >>= checkReturn++checkReturn :: CString -> IO (Maybe String)+checkReturn r+ | r == nullPtr = return Nothing+ | otherwise = fmap Just $ peekCString r
setlocale.cabal view
@@ -1,15 +1,25 @@-Name: setlocale-Version: 0.0.3-Cabal-Version: >= 1.2-Build-Type: Simple-License: PublicDomain-Author: Lukas Mai-Maintainer: l.mai @web.de-Synopsis: A Haskell interface to setlocale()-Description: A Haskell interface to @setlocale()@.-Category: System+-- Initial setlocale.cabal generated by cabal init. For further +-- documentation, see http://haskell.org/cabal/users-guide/ -Library- Exposed-Modules: System.Locale.SetLocale- Build-Depends: base- Ghc-Options: -O2 -Wall+name: setlocale+version: 1.0.0+synopsis: Haskell bindings to setlocale+-- description: +license: BSD3+license-file: LICENSE+author: Sven Bartscher+maintainer: sven.bartscher@weltraumschlangen.de+copyright: 2014, Sven Bartscher+category: System+build-type: Simple+-- extra-source-files: +cabal-version: >=1.10++library+ exposed-modules: System.Locale.SetLocale+ -- other-modules: + other-extensions: DeriveDataTypeable, ForeignFunctionInterface+ build-depends: base >=4.6 && <4.7+ -- hs-source-dirs: + build-tools: hsc2hs+ default-language: Haskell98