Hi there,

I added basic support for converting GStrings to Haskell Strings. The function
readGString works really well so far.

Andreas

1 patch for repository http://code.haskell.org/gtk2hs:

Mon Nov 15 11:31:57 CET 2010  Andreas Baldeau <andr...@baldeau.net>
  * Added basic GString support.


New patches:

[Added basic GString support.
Andreas Baldeau <andr...@baldeau.net>**20101115103157
 Ignore-this: 4fc62813b652cc6e420c7b69006dfdae
] addfile ./glib/System/Glib/GString.chs
hunk ./glib/System/Glib/GString.chs 1
+-- -*-haskell-*-
+--  GIMP Toolkit (GTK)
+--
+--  Author : Andreas Baldeau
+--
+--  Created: 14 November 2010
+--
+--  Copyright (C) 2010 Andreas Baldeau
+--
+--  This library is free software; you can redistribute it and/or
+--  modify it under the terms of the GNU Lesser General Public
+--  License as published by the Free Software Foundation; either
+--  version 2.1 of the License, or (at your option) any later version.
+--
+--  This library 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
+--  Lesser General Public License for more details.
+--
+-- |
+-- Maintainer  : gtk2hs-us...@lists.sourceforge.net
+-- Stability   : provisional
+-- Portability : portable (depends on GHC)
+--
+-- Defines functions to extract data from a GString.
+--
+module System.Glib.GString (
+  GString,
+  readGString,
+  fromGString,
+  ) where
+
+import Foreign
+import Control.Exception       (bracket)
+import Control.Monad           (foldM)
+
+import System.Glib.FFI
+
+{# context lib="glib" prefix="g" #}
+
+{#pointer * GString#}
+
+-- methods
+
+-- Turn a GString into a String but don't destroy it.
+--
+readGString :: GString -> IO (Maybe String)
+readGString gstring
+  | gstring == nullPtr = return Nothing
+  | otherwise         = do
+    gstr <- {#get GString->str#} gstring
+    maybePeek peekCString gstr
+
+-- Turn a GList into a list of pointers (freeing the GList in the process).
+--
+fromGString :: GString -> IO (Maybe String)
+fromGString gstring
+  | gstring == nullPtr = return Nothing
+  | otherwise         = do
+    gstr <- {#get GString->str#} gstring
+    str  <- maybePeek peekCString gstr
+    _ <- {#call unsafe string_free#} gstring $ fromBool True
+    return str
+
hunk ./glib/glib.cabal 60
                           System.Glib.UTFString
                           System.Glib.Types
                           System.Glib.GList
+                          System.Glib.GString
                           System.Glib.GType
                           System.Glib.GTypeConstants
                           System.Glib.GValue

Context:

[TAG 0.12.0
axel.si...@in.tum.de**20101107135304
 Ignore-this: 14b3023f48c36eed2cb136a2b69d6dae
] 
Patch bundle hash:
297281715c871e70b51eadc13e75a45ce429bd6f
------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to