@@ -90,11 +90,11 @@ parse src = do
90 if err /= nullPtr then do
90 if err /= nullPtr then do
91 bs <- BS.packCString =<< hexml_document_error doc
91 bs <- BS.packCString =<< hexml_document_error doc
92 hexml_document_free doc
92 hexml_document_free doc
93− return $ Left bs
93+ pure $ Left bs
95 node <- hexml_document_node doc
95 node <- hexml_document_node doc
96 doc <- newForeignPtr hexml_document_free_funptr doc
96 doc <- newForeignPtr hexml_document_free_funptr doc
97− return $ Right $ Node src0 doc node
97+ pure $ Right $ Node src0 doc node
99-- | Given a node, rerender it to something with an equivalent parse tree.
99-- | Given a node, rerender it to something with an equivalent parse tree.
100-- Mostly useful for debugging - if you want the real source document use 'outer' instead.
100-- Mostly useful for debugging - if you want the real source document use 'outer' instead.
@@ -103,7 +103,7 @@ render (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
103 i <- hexml_node_render d n nullPtr 0
103 i <- hexml_node_render d n nullPtr 0
104 res <- BS.create (fromIntegral i) $ \ptr -> void $ hexml_node_render d n (castPtr ptr) i
104 res <- BS.create (fromIntegral i) $ \ptr -> void $ hexml_node_render d n (castPtr ptr) i
105 touchBS src
105 touchBS src
106− return res
106+ pure res
108applyStr :: BS.ByteString -> Str -> BS.ByteString
108applyStr :: BS.ByteString -> Str -> BS.ByteString
109applyStr bs Str{..} = BS.take (fromIntegral strLength) $ BS.drop (fromIntegral strStart) bs
109applyStr bs Str{..} = BS.take (fromIntegral strLength) $ BS.drop (fromIntegral strStart) bs
@@ -118,7 +118,7 @@ attrPeek :: BS.ByteString -> ForeignPtr CDocument -> Ptr CAttr -> Attribute
118attrPeek src doc a = unsafePerformIO $ withForeignPtr doc $ \_ -> do
118attrPeek src doc a = unsafePerformIO $ withForeignPtr doc $ \_ -> do
119 name <- applyStr src <$> peekElemOff (castPtr a) 0
119 name <- applyStr src <$> peekElemOff (castPtr a) 0
120 val <- applyStr src <$> peekElemOff (castPtr a) 1
120 val <- applyStr src <$> peekElemOff (castPtr a) 1
121− return $ Attribute name val
121+ pure $ Attribute name val
123-- | Get the name of a node, e.g. @\<test /\>@ produces @\"test\"@.
123-- | Get the name of a node, e.g. @\<test /\>@ produces @\"test\"@.
124name :: Node -> BS.ByteString
124name :: Node -> BS.ByteString
@@ -156,7 +156,7 @@ children (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d ->
156 alloca $ \count -> do
156 alloca $ \count -> do
157 res <- hexml_node_children d n count
157 res <- hexml_node_children d n count
158 count <- fromIntegral <$> peek count
158 count <- fromIntegral <$> peek count
159− return [Node src doc $ plusPtr res $ i*szNode | i <- [0..count-1]]
159+ pure [Node src doc $ plusPtr res $ i*szNode | i <- [0..count-1]]
161-- | Get the attributes of this node.
161-- | Get the attributes of this node.
162attributes :: Node -> [Attribute]
162attributes :: Node -> [Attribute]
@@ -164,7 +164,7 @@ attributes (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d ->
164 alloca $ \count -> do
164 alloca $ \count -> do
165 res <- hexml_node_attributes d n count
165 res <- hexml_node_attributes d n count
166 count <- fromIntegral <$> peek count
166 count <- fromIntegral <$> peek count
167− return [attrPeek src doc $ plusPtr res $ i*szAttr | i <- [0..count-1]]
167+ pure [attrPeek src doc $ plusPtr res $ i*szAttr | i <- [0..count-1]]
169-- | Get the direct children of this node which have a specific name.
169-- | Get the direct children of this node which have a specific name.
170-- A more efficient version of:
170-- A more efficient version of:
@@ -177,7 +177,7 @@ childrenBy (Node src doc n) str = go nullPtr
177 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
177 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
178 r <- hexml_node_child d n old bs $ fromIntegral len
178 r <- hexml_node_child d n old bs $ fromIntegral len
179 touchBS src
179 touchBS src
180− return $ if r == nullPtr then [] else Node src doc r : go r
180+ pure $ if r == nullPtr then [] else Node src doc r : go r
182-- | Get the first attribute of this node which has a specific name, if there is one.
182-- | Get the first attribute of this node which has a specific name, if there is one.
183-- A more efficient version of:
183-- A more efficient version of:
@@ -188,7 +188,7 @@ attributeBy (Node src doc n) str = unsafePerformIO $ withForeignPtr doc $ \d ->
188 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
188 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
189 r <- hexml_node_attribute d n bs $ fromIntegral len
189 r <- hexml_node_attribute d n bs $ fromIntegral len
190 touchBS src
190 touchBS src
191− return $ if r == nullPtr then Nothing else Just $ attrPeek src doc r
191+ pure $ if r == nullPtr then Nothing else Just $ attrPeek src doc r
193-- | Find the starting location of a node, the @<@ character.
193-- | Find the starting location of a node, the @<@ character.
194-- The first character will be reported as @(line 1,column 1)@, because thats
194-- The first character will be reported as @(line 1,column 1)@, because thats