@@ -4,10 +4,10 @@
44-- Note that entities, e.g. @&@, are not expanded.
55module Text.XML.Hexml(
66 Node, Attribute(..),
7− nodeParse, nodeRender,
8− nodeName, nodeInner, nodeOuter,
9− nodeAttributes, nodeChildren, nodeContents,
10− nodeAttributeBy, nodeChildrenBy
7+ parse, render,
8+ name, inner, outer,
9+ attributes, children, contents,
10+ attributeBy, childrenBy
1111 ) where
1212
1313import Control.Applicative
@@ -64,11 +64,11 @@ data Node = Node BS.ByteString (ForeignPtr CDocument) (Ptr CNode)
6464data Attribute = Attribute BS.ByteString BS.ByteString deriving (Show, Eq, Ord)
6565
6666instance Show Node where
67− show d = "Node " ++ show (BS.unpack $ nodeOuter d)
67+ show d = "Node " ++ show (BS.unpack $ outer d)
6868
6969
70−nodeParse :: BS.ByteString -> Either BS.ByteString Node
71−nodeParse src = unsafePerformIO $ BS.unsafeUseAsCStringLen (src <> BS.singleton '\0') $ \(str, len) -> do
70+parse :: BS.ByteString -> Either BS.ByteString Node
71+parse src = unsafePerformIO $ BS.unsafeUseAsCStringLen (src <> BS.singleton '\0') $ \(str, len) -> do
7272 doc <- document_parse str (fromIntegral len - 1)
7373 err <- document_error doc
7474 if err /= nullPtr then do
@@ -80,8 +80,8 @@ nodeParse src = unsafePerformIO $ BS.unsafeUseAsCStringLen (src <> BS.singleton
8080 doc <- newForeignPtr document_free_funptr doc
8181 return $ Right $ Node src doc node
8282
83−nodeRender :: Node -> BS.ByteString
84−nodeRender (Node _ doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
83+render :: Node -> BS.ByteString
84+render (Node _ doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
8585 i <- node_render d n nullPtr 0
8686 BS.create (fromIntegral i) $ \ptr -> void $ node_render d n (castPtr ptr) i
8787
@@ -100,17 +100,17 @@ attrPeek src doc a = unsafePerformIO $ withForeignPtr doc $ \_ -> do
100100 val <- applyStr src <$> peekElemOff (castPtr a) 1
101101 return $ Attribute name val
102102
103−nodeName :: Node -> BS.ByteString
104−nodeName = nodeBS 0
103+name :: Node -> BS.ByteString
104+name = nodeBS 0
105105
106−nodeInner :: Node -> BS.ByteString
107−nodeInner = nodeBS 1
106+inner :: Node -> BS.ByteString
107+inner = nodeBS 1
108108
109−nodeOuter :: Node -> BS.ByteString
110−nodeOuter = nodeBS 2
109+outer :: Node -> BS.ByteString
110+outer = nodeBS 2
111111
112−nodeContents :: Node -> [Either BS.ByteString Node]
113−nodeContents n@(Node src _ _) = f (strStart inner) outers
112+contents :: Node -> [Either BS.ByteString Node]
113+contents n@(Node src _ _) = f (strStart inner) outers
114114 where
115115 f i [] = string i (strEnd inner) ++ []
116116 f i ((x, n):xs) = string i (strStart x) ++ Right n : f (strEnd x) xs
@@ -118,32 +118,32 @@ nodeContents n@(Node src _ _) = f (strStart inner) outers
118118 string start end | start == end = []
119119 | otherwise = [Left $ applyStr src $ Str start (end - start)]
120120 inner = nodeStr 1 n
121− outers = map (nodeStr 2 &&& id) $ nodeChildren n
121+ outers = map (nodeStr 2 &&& id) $ children n
122122
123−nodeChildren :: Node -> [Node]
124−nodeChildren (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
123+children :: Node -> [Node]
124+children (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
125125 alloca $ \count -> do
126126 res <- node_children d n count
127127 count <- fromIntegral <$> peek count
128128 return [Node src doc $ plusPtr res $ i*szNode | i <- [0..count-1]]
129129
130−nodeAttributes :: Node -> [Attribute]
131−nodeAttributes (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
130+attributes :: Node -> [Attribute]
131+attributes (Node src doc n) = unsafePerformIO $ withForeignPtr doc $ \d -> do
132132 alloca $ \count -> do
133133 res <- node_attributes d n count
134134 count <- fromIntegral <$> peek count
135135 return [attrPeek src doc $ plusPtr res $ i*szAttr | i <- [0..count-1]]
136136
137−nodeChildrenBy :: Node -> BS.ByteString -> [Node]
138−nodeChildrenBy (Node src doc n) str = go nullPtr
137+childrenBy :: Node -> BS.ByteString -> [Node]
138+childrenBy (Node src doc n) str = go nullPtr
139139 where
140140 go old = unsafePerformIO $ withForeignPtr doc $ \d ->
141141 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
142142 r <- node_childBy d n old bs $ fromIntegral len
143143 return $ if r == nullPtr then [] else Node src doc r : go r
144144
145−nodeAttributeBy :: Node -> BS.ByteString -> Maybe Attribute
146−nodeAttributeBy (Node src doc n) str = unsafePerformIO $ withForeignPtr doc $ \d ->
145+attributeBy :: Node -> BS.ByteString -> Maybe Attribute
146+attributeBy (Node src doc n) str = unsafePerformIO $ withForeignPtr doc $ \d ->
147147 BS.unsafeUseAsCStringLen str $ \(bs, len) -> do
148148 r <- node_attributeBy d n bs $ fromIntegral len
149149 return $ if r == nullPtr then Nothing else Just $ attrPeek src doc r