From: Duncan C. <dun...@us...> - 2005-04-05 18:13:53
|
Update of /cvsroot/gtk2hs/gtk2hs/glib/System/Glib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18131/glib/System/Glib Modified Files: UTFString.hs Log Message: Add some extra functions for marshaling lists and arrays of UTF-8 strings. Index: UTFString.hs =================================================================== RCS file: /cvsroot/gtk2hs/gtk2hs/glib/System/Glib/UTFString.hs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- UTFString.hs 16 Jan 2005 21:40:33 -0000 1.2 +++ UTFString.hs 5 Apr 2005 18:13:42 -0000 1.3 @@ -33,6 +33,9 @@ peekUTFStringLen, readUTFString, readCString, + withUTFStrings, + withUTFStringArray, + withUTFStringArray0, ) where import Monad (liftM) @@ -87,6 +90,29 @@ free (castPtr strPtr) return str +-- Temporarily allocate a list of UTF-8 Strings. +-- +withUTFStrings :: [String] -> ([CString] -> IO a) -> IO a +withUTFStrings hsStrs = withUTFStrings' hsStrs [] + where withUTFStrings' :: [String] -> [CString] -> ([CString] -> IO a) -> IO a + withUTFStrings' [] cs body = body (reverse cs) + withUTFStrings' (s:ss) cs body = withUTFString s $ \c -> + withUTFStrings' ss (c:cs) body + +-- Temporarily allocate an array of UTF-8 Strings. +-- +withUTFStringArray :: [String] -> (Ptr CString -> IO a) -> IO a +withUTFStringArray hsStr body = + withUTFStrings hsStr $ \cStrs -> do + withArray cStrs body + +-- Temporarily allocate a null-terminated array of UTF-8 Strings. +-- +withUTFStringArray0 :: [String] -> (Ptr CString -> IO a) -> IO a +withUTFStringArray0 hsStr body = + withUTFStrings hsStr $ \cStrs -> do + withArray0 nullPtr cStrs body + -- Convert Unicode characters to UTF-8. -- toUTF :: String -> String |