@@ -24,27 +24,25 @@ module Text.XML.DOM.Parser.Combinators
2424 , checkCurrentName
2525 -- * Parsing element's content
2626 , parseContent
27− , readContent
28− , maybeReadContent
2927 -- * Parsing attributes
3028 , parseAttribute
3129 , parseAttributeMaybe
3230 ) where
3331
34−import Control.Lens
35−import Control.Monad.Except
36−import Control.Monad.Reader
37−import Data.List.NonEmpty (NonEmpty(..))
38−import qualified Data.Map.Strict as M
39−import Data.Monoid
40−import Data.Text (Text)
41−import qualified Data.Text as T
42−import Data.Traversable
43−import Data.Typeable
44−import Text.Read
45−import Text.XML
46−import Text.XML.DOM.Parser.Types
47−import Text.XML.Lens
32+import Control.Lens
33+import Control.Monad.Except
34+import Control.Monad.Reader
35+import Data.Foldable as F
36+import Data.List as L
37+import Data.List.NonEmpty (NonEmpty(..))
38+import Data.Map.Strict as M
39+import Data.Monoid
40+import Data.Text as T
41+import Data.Traversable
42+import Text.XML
43+import Text.XML.DOM.Parser.Common
44+import Text.XML.DOM.Parser.Types
45+import Text.XML.Lens
4846
4947
5048-- | Generic function to traverse arbitrary inner cursors.
@@ -156,9 +154,9 @@ divePath path = magnify $ to modElems
156154 where
157155 modElems
158156 = over pdElements (toListOf $ folded . diver)
159− . over pdPath (<> DomPath (map _nmShow path))
157+ . over pdPath (<> DomPath (L.map _nmShow path))
160158 diver :: Fold Element Element
161− diver = foldr (.) id $ map toDive path
159+ diver = F.foldr (.) id $ L.map toDive path
162160 toDive n = nodes . folded . _Element . elMatchName n
163161
164162diveElem
@@ -190,7 +188,7 @@ ignoreEmpty
190188 -> DomParserT Identity m (Maybe a)
191189ignoreEmpty = ignoreElem test
192190 where
193− test e = null $ e ^. nodes
191+ test e = L.null $ e ^. nodes
194192
195193-- | If all current elements contains blank content, or contains nothing at all
196194-- , then returns Nothing, else runs parser.
@@ -204,7 +202,7 @@ ignoreBlank = ignoreElem test
204202 let
205203 elems = e ^.. nodes . folded . _Element
206204 cont = mconcat $ e ^.. nodes . folded . _Content
207− in if | not $ null elems -> False
205+ in if | not $ L.null elems -> False
208206 | T.null $ T.strip cont -> True
209207 | otherwise -> False
210208
@@ -225,7 +223,7 @@ checkCurrentName n = do
225223 cn <- getCurrentName
226224 unless ((n ^. nmMatch) cn) $ do
227225 p <- view pdPath
228− let pinit = if null (unDomPath p) then [] else init $ unDomPath p
226+ let pinit = if L.null (unDomPath p) then [] else L.init $ unDomPath p
229227 throwError $ ParserErrors [PENotFound $ DomPath $ pinit ++ [_nmShow n]]
230228 return ()
231229
@@ -242,8 +240,8 @@ getCurrentContent = do
242240 conts :: [Text]
243241 conts = nds ^.. folded . _Content
244242 return $ if
245− | not $ null els -> Nothing
246− | null conts -> Nothing
243+ | not $ L.null els -> Nothing
244+ | L.null conts -> Nothing
247245 | otherwise -> Just $ mconcat conts
248246
249247-- | Parses content inside current tag. It expects current element set
@@ -260,31 +258,6 @@ parseContent parse = getCurrentContent >>= \case
260258 Left e -> throwParserError $ PEWrongFormat e
261259 Right a -> return a
262260
263−-- | If reader returns 'Nothing' then resulting function returns 'Left
264−-- "error message"'
265−--
266−-- @since 1.0.0
267−maybeReadContent
268− :: forall a
269− . (Typeable a)
270− => (Text -> Maybe a)
271− -- ^ Content or attribute reader
272− -> Text
273− -- ^ Content or attribute value
274− -> Either Text a
275−maybeReadContent f t = maybe (Left msg) Right $ f t
276− where
277− msg = "Not readable " <> n <> ": " <> t
278− n = T.pack $ show $ typeRep (Proxy :: Proxy a)
279−
280−-- | Tries to read given text to value using 'Read'. Useful to use
281−-- with 'parseContent' and 'parseAttribute'
282−readContent
283− :: (Read a, Typeable a)
284− => Text
285− -> Either Text a
286−readContent = maybeReadContent $ readMaybe . T.unpack . T.strip
287−
288261-- | Retuns map of attributes of current element
289262--
290263-- @since 1.0.0