[Fencommits] fenfire-hs: skip namespaces that have null prefix or uri in raptor

Tuukka Hastrup Tuukka.Hastrup at iki.fi
Wed Mar 7 01:36:09 EET 2007


Wed Mar  7 01:35:51 EET 2007  Tuukka Hastrup <Tuukka.Hastrup at iki.fi>
  * skip namespaces that have null prefix or uri in raptor
diff -rN -u old-fenfire-hs/Raptor.chs new-fenfire-hs/Raptor.chs
--- old-fenfire-hs/Raptor.chs	2007-03-07 01:36:08.000000000 +0200
+++ new-fenfire-hs/Raptor.chs	2007-03-07 01:36:08.000000000 +0200
@@ -112,13 +112,16 @@
 getObject (Statement s) = mkIdentifier ({#get statement->object#} s)
                                        ({#get statement->object_type#} s)
                                        
-getNamespace :: Namespace -> IO (String, String)
+getNamespace :: Namespace -> IO (Maybe String, Maybe String)
 getNamespace ns = do
     prefixC <- {#call raptor_namespace_get_prefix#} ns
-    prefixS <- peekUTFString (castPtr prefixC)
+    prefixS <- if prefixC == nullPtr
+                   then return Nothing
+                   else fmap Just $ peekUTFString (castPtr prefixC)
     uri <- {#call raptor_namespace_get_uri#} ns
     uriC <- {#call uri_as_string#} (castPtr uri)
-    uriS <- peekUTFString (castPtr uriC)
+    uriS <- if uriC == nullPtr then return Nothing
+                               else fmap Just $ peekUTFString (castPtr uriC)
     return (prefixS, uriS)
 
 withURI :: String -> (Ptr URI -> IO a) -> IO a
@@ -269,7 +272,9 @@
 
   nsHandler <- mkNamespaceHandler $ \_user_data ns -> do
     (prefix, uri') <- getNamespace ns
-    modifyIORef namespaces ((prefix, uri'):)
+    case (prefix, uri') of 
+        (Just prefix',Just uri'') -> modifyIORef namespaces ((prefix', uri''):)
+        _                         -> return ()
 
   let msgHandler intro = mkMessageHandler $ \_user_data locator msg -> do
         size <- {# call format_locator #} nullPtr 0 locator




More information about the Fencommits mailing list