@@ -78,17 +78,19 @@ instance Show Node where
78-- Often the first child will be the @\<?xml ... ?\>@ element. For documents which comprise a single
78-- Often the first child will be the @\<?xml ... ?\>@ element. For documents which comprise a single
79-- root element, use @'children' n !! 1@.
79-- root element, use @'children' n !! 1@.
80parse :: BS.ByteString -> Either BS.ByteString Node
80parse :: BS.ByteString -> Either BS.ByteString Node
81−parse src = unsafePerformIO $ BS.unsafeUseAsCStringLen (src <> BS.singleton '\0') $ \(str, len) -> do
81+parse src = do
82+ let src0 = src <> BS.singleton '\0'
83+ unsafePerformIO $ BS.unsafeUseAsCStringLen src0 $ \(str, len) -> do
82− doc <- document_parse str (fromIntegral len - 1)
84+ doc <- document_parse str (fromIntegral len - 1)
83− err <- document_error doc
85+ err <- document_error doc
84− if err /= nullPtr then do
86+ if err /= nullPtr then do
85− bs <- BS.packCString =<< document_error doc
87+ bs <- BS.packCString =<< document_error doc
86− document_free doc
88+ document_free doc
87− return $ Left bs
89+ return $ Left bs
89− node <- document_node doc
91+ node <- document_node doc
90− doc <- newForeignPtr document_free_funptr doc
92+ doc <- newForeignPtr document_free_funptr doc
91− return $ Right $ Node src doc node
93+ return $ Right $ Node src0 doc node
93-- | Given a node, rerender it to something with an equivalent parse tree.
95-- | Given a node, rerender it to something with an equivalent parse tree.
94-- Mostly useful for debugging - if you want the real source document use 'outer' instead.
96-- Mostly useful for debugging - if you want the real source document use 'outer' instead.