packages feed

html-entity 0.1.0.0 → 0.1.1.0

raw patch · 3 files changed

+34/−13 lines, 3 filesdep ~base-compatPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base-compat

API changes (from Hackage documentation)

+ Text.HTMLEntity: decodePartial :: Text -> Result Text
+ Text.HTMLEntity: encodePartial :: Text -> Result Text

Files

html-entity.cabal view
@@ -1,5 +1,5 @@ name:               html-entity-version:            0.1.0.0+version:            0.1.1.0 synopsis:           HTML entity decoding and encoding for Text description:        Fast, attoparsec-powered HTML entity decoding and encoding for Text license:            BSD3@@ -38,7 +38,7 @@   hs-source-dirs:     src   build-depends:      base                 == 4.*                     , attoparsec-                    , base-compat          == 0.10.*+                    , base-compat          >= 0.9                     , text                     , unordered-containers   default-language:   Haskell2010
src/Text/HTMLEntity.hs view
@@ -1,9 +1,17 @@ -- | Efficient decoding and encoding of HTML entities in text.-module Text.HTMLEntity where+module Text.HTMLEntity+    ( -- * Usage+      decode+    , decode'+    , encode+    -- ** Partial decoding/encoding+    -- $partial+    , decodePartial+    , encodePartial+    ) where  import Data.Attoparsec.Text import Data.Text (Text)-import qualified Data.Text as T import Prelude.Compat import Text.HTMLEntity.Parser @@ -11,6 +19,7 @@ -- >>> :set -XOverloadedStrings -- >>> import qualified Data.Text.IO as T +-- *** Decoding/encoding -- | Decode HTML entities contained in the given text. Returns -- @Left decodeError@ on failure. The parser will do its best to explain -- the problem.@@ -27,9 +36,7 @@ -- >>> decode "�" -- Left "entity: Failed reading: 4294967295 is out of Char range" decode :: Text -> Either String Text-decode t-    | T.null t = Right t-decode x = parseOnly decodeParser x+decode = parseOnly decodeParser {-# INLINE decode #-}  -- | Like 'decode', except that if a decode error occurs, the original@@ -62,3 +69,18 @@ encode :: Text -> Text encode = either (error "html-entity internal encoding error") id . parseOnly encodeParser {-# INLINE encode #-}++{- $partial+These functions are provided for convenience if you're using attoparsec+in a streaming style, and all return 'Result' values. Use them as you+would normally.+-}+-- | Partial 'decode'.+decodePartial :: Text -> Result Text+decodePartial = parse decodeParser+{-# INLINE decodePartial #-}++-- | Partial 'encode'.+encodePartial :: Text -> Result Text+encodePartial = parse encodeParser+{-# INLINE encodePartial #-}
src/Text/HTMLEntity/Parser.hs view
@@ -10,16 +10,15 @@ import Data.Ix import Data.Monoid.Compat import qualified Data.Text as T-import qualified Text.HTMLEntity.Table as Table import Prelude.Compat+import qualified Text.HTMLEntity.Table as Table  decodeParser :: Parser T.Text-decodeParser =-    liftA2-        (<>)-        ((A.takeWhile1 (/= '&') <?> "plain text") <|> (ent <?> "entity"))-        (eof <|> decodeParser)+decodeParser = go   where+    go =+        eof <|>+        liftA2 (<>) ((A.takeWhile1 (/= '&') <?> "plain text") <|> (ent <?> "entity")) go     eof = "" <$ endOfInput     ent = do         void $ char '&'