hxt-pickle-utils (empty) → 0.1
raw patch · 5 files changed
+103/−0 lines, 5 filesdep +basedep +hxtdep +mtlsetup-changed
Dependencies added: base, hxt, mtl
Files
- LICENSE +30/−0
- README.md +4/−0
- Setup.hs +2/−0
- hxt-pickle-utils.cabal +26/−0
- src/Text/Xml/Pickle.hs +41/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Silk++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Silk nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,4 @@+hxt-pickle-utils+================++Utility functions for using HXT picklers.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hxt-pickle-utils.cabal view
@@ -0,0 +1,26 @@+name: hxt-pickle-utils+version: 0.1+synopsis: Utility functions for using HXT picklers.+description: Utility functions for using HXT picklers.+homepage: https://github.com/silkapp/hxt-pickle-utils+license: BSD3+license-file: LICENSE+author: Silk+maintainer: code@silk.co+copyright: (c) 2014, Silk+category: XML+build-type: Simple+extra-source-files: README.md+cabal-version: >=1.10++library+ exposed-modules: Text.Xml.Pickle+ build-depends: base >= 4.5 && < 4.7+ , hxt >= 9.2 && < 9.4+ , mtl >= 2.0 && < 2.2+ hs-source-dirs: src+ default-language: Haskell2010++source-repository head+ Type: git+ Location: https://github.com/silkapp/hxt-pickle-utils.git
+ src/Text/Xml/Pickle.hs view
@@ -0,0 +1,41 @@+-- | Some utility functions for using hxt picklers.+module Text.Xml.Pickle+ ( toXML+ , fromXML+ , maybeFromXML+ , eitherFromXML+ ) where++import Control.Monad.Identity+import Control.Category+import Prelude hiding ((.))+import Text.XML.HXT.Core++-- | Convert a value to an XML string.+toXML :: XmlPickler p => p -> String+toXML = showPickled []++-- | Parse a string containing xml to a value. On parse failure, will+-- call `error`.+fromXML :: XmlPickler a => String -> a+fromXML = runIdentity . fromXMLM++-- | Parse a string containing xml to a value, or `Nothing` if the+-- parse fails.+maybeFromXML :: XmlPickler a => String -> Maybe a+maybeFromXML = fromXMLM++-- | Parse a string containing xml to a value, or an error message on+-- failure.+eitherFromXML :: XmlPickler a => String -> Either String a+eitherFromXML text =+ case runLA (removeAllWhiteSpace . xread) text of+ [] -> Left "Failed to parse XML in eitherFromXML."+ [x] -> unpickleDoc' xpickle x+ (_:_) -> Left "Multiple parses in eitherFromXML."++fromXMLM :: (Monad m, XmlPickler a) => String -> m a+fromXMLM text = case runLA (removeAllWhiteSpace . xread) text of+ [] -> fail "Failed to parse XML in fromXMLM."+ [x] -> either fail return $ unpickleDoc' xpickle x+ (_:_) -> fail "Multiple parses in fromXMLM."