~singpolyma/xml-types-haskell

f2ffe348b6898644bc4906c3354ac67117f57de1 — John Millikin 11 years ago 9343c14 xml-types_0.2
Make ``elementText`` and ``nodeText`` return lists, so they work as
standard combinators.
1 files changed, 11 insertions(+), 9 deletions(-)

M Data/XML/Types.hs
M Data/XML/Types.hs => Data/XML/Types.hs +11 -9
@@ 277,8 277,8 @@ elementChildren = elementNodes >=> isElement
elementContent :: Element -> [Content]
elementContent = elementNodes >=> isContent

elementText :: Element -> Text
elementText = contentText . elementContent
elementText :: Element -> [Text]
elementText = elementContent >=> contentText

nodeChildren :: Node -> [Node]
nodeChildren = isElement >=> elementNodes


@@ 286,8 286,8 @@ nodeChildren = isElement >=> elementNodes
nodeContent :: Node -> [Content]
nodeContent = nodeChildren >=> isContent

nodeText :: Node -> Text
nodeText = contentText . nodeContent
nodeText :: Node -> [Text]
nodeText = nodeContent >=> contentText

hasAttribute :: Name -> Element -> [Element]
hasAttribute name e = [e | isJust (attributeContent name e)]


@@ 299,12 299,14 @@ attributeContent :: Name -> Element -> Maybe [Content]
attributeContent name e = M.lookup name (elementAttributes e)

attributeText :: Name -> Element -> Maybe Text
attributeText name e = fmap contentText (attributeContent name e)
attributeText name e = fmap contentFlat (attributeContent name e)

contentText :: [Content] -> Text
contentText = T.concat . map step where
	step (ContentText t) = t
	step (ContentEntity entity) = T.concat [T.pack "&", entity, T.pack ";"]
contentText :: Content -> [Text]
contentText (ContentText t) = [t]
contentText (ContentEntity entity) = [T.pack "&", entity, T.pack ";"]

contentFlat :: [Content] -> Text
contentFlat cs = T.concat (cs >>= contentText)

typeString :: String -> a -> TypeRep
typeString str _ = mkTyConApp (mkTyCon ("Data.XML.Types." ++ str)) []