module Text.XML.Expat.Lens.Names (
prefix, namespace, qualified, namespaced,
HasLocalPart (..)
) where
import Control.Applicative
import Control.Exception
import Control.Lens hiding (children)
import Text.XML.Expat.Tree
import Control.DeepSeq
import System.IO.Unsafe
class HasLocalPart a where
localPart :: Lens' (a t) t
prefix :: Lens' (QName text) (Maybe text)
prefix inj (QName pref part) = (`QName` part) <$> inj pref
instance HasLocalPart QName where
localPart inj (QName pref part) = QName pref <$> inj part
namespace :: Lens' (NName text) (Maybe text)
namespace inj (NName ns part) = (`NName` part) <$> inj ns
instance HasLocalPart NName where
localPart inj (NName ns part) = NName ns <$> inj part
qualified ::
(GenericXMLString text, NodeClass n c) =>
Iso' (n c text text) (n c (QName text) text)
qualified = iso toQualified fromQualified
namespaced ::
( GenericXMLString text, NodeClass n c
, Show text, Ord text, NFData (n c (NName text) text) ) =>
Prism' (n c (QName text) text)
(n c (NName text) text)
namespaced = prism' fromNamespaced (muspoon . toNamespaced)
muspoon :: NFData a => a -> Maybe a
muspoon a = unsafePerformIO $ deepseq a (Just `fmap` return a) `catches` handles
where handles = [ Handler $ \(_ :: ErrorCall) -> return Nothing ]