Skip to content

Commit

Permalink
update feed parser for new-style HaXml API
Browse files Browse the repository at this point in the history
patch by Iain Lane <laney@debian.org>
taken from twidge 1.0.8.1+nmu1 in Debian
  • Loading branch information
David Banks committed Aug 26, 2012
1 parent a06fe54 commit 1c39c0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions FeedParser.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Written by John Goerzen, jgoerzen\@complete.org
module FeedParser where module FeedParser where


import Text.XML.HaXml import Text.XML.HaXml
import Text.XML.HaXml.Posn
import Data.Char import Data.Char
import Data.List import Data.List
import Data.String.Utils(strip) import Data.String.Utils(strip)
Expand All @@ -44,16 +45,16 @@ An implementation without unescaping would simply be:
Because HaXml's unescaping only works on Elements, we must make sure that Because HaXml's unescaping only works on Elements, we must make sure that
whatever Content we have is wrapped in an Element, then use txt to whatever Content we have is wrapped in an Element, then use txt to
pull the insides back out. -} pull the insides back out. -}
contentToString :: [Content] -> String contentToString :: [Content Posn] -> String
contentToString = contentToString =
concatMap procContent concatMap procContent
where procContent x = where procContent x =
verbatim $ keep /> txt $ CElem (unesc (fakeElem x)) verbatim $ keep /> txt $ CElem (unesc (fakeElem x)) noPos


fakeElem :: Content -> Element fakeElem :: Content a -> Element a
fakeElem x = Elem "fake" [] [x] fakeElem x = Elem "fake" [] [x]


unesc :: Element -> Element unesc :: Element a -> Element a
unesc = xmlUnEscape stdXmlEscaper unesc = xmlUnEscape stdXmlEscaper


stripUnicodeBOM :: String -> String stripUnicodeBOM :: String -> String
Expand All @@ -67,4 +68,4 @@ sanitize = strip . map sanitizer
| c `elem` "\n\r\0\t" = ' ' | c `elem` "\n\r\0\t" = ' '
| otherwise = c | otherwise = c


getContent (Document _ _ e _) = CElem e getContent (Document _ _ e _) = CElem e noPos
2 changes: 1 addition & 1 deletion twidge.cabal
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Flag withBitly


Executable twidge Executable twidge
Build-Depends: network, unix, parsec, MissingH>=1.0.0, Build-Depends: network, unix, parsec, MissingH>=1.0.0,
mtl, base >= 4 && < 5, HaXml>=1.13.2, HaXml<1.19, hslogger, hoauth>=0.2.3 && <0.2.4, mtl, base >= 4 && < 5, HaXml>=1.14, hslogger, hoauth>=0.2.3 && <0.2.4,
ConfigFile, directory, HSH, regex-posix, utf8-string, binary, ConfigFile, directory, HSH, regex-posix, utf8-string, binary,
bytestring, curl, old-locale, time bytestring, curl, old-locale, time


Expand Down

0 comments on commit 1c39c0e

Please sign in to comment.