module Text.XML.Expat.Internal.Qualified (
QName(..),
QAttributes,
mkQName,
mkAnQName,
toQualified,
fromQualified
) where
import Text.XML.Expat.Internal.NodeClass
import Text.XML.Expat.SAX
import Control.DeepSeq
import Data.Monoid
data QName text =
QName {
qnPrefix :: Maybe text,
qnLocalPart :: !text
}
deriving (Eq,Show)
instance NFData text => NFData (QName text) where
rnf (QName pre loc) = rnf (pre, loc)
type QAttributes text = Attributes (QName text) text
mkQName :: text -> text -> QName text
mkQName prefix localPart = QName (Just prefix) localPart
mkAnQName :: text -> QName text
mkAnQName localPart = QName Nothing localPart
toQualified :: (NodeClass n c, GenericXMLString text) => n c text text -> n c (QName text) text
toQualified = mapAllTags qual
where
qual ident =
case gxBreakOn ':' ident of
(prefix, _local) | not (gxNullString _local)
&& gxHead _local == ':'
-> QName (Just prefix) (gxTail _local)
_ -> QName Nothing ident
fromQualified :: (NodeClass n c, GenericXMLString text) => n c (QName text) text -> n c text text
fromQualified = mapAllTags tag
where
tag (QName (Just prefix) local) = prefix `mappend` gxFromChar ':' `mappend` local
tag (QName Nothing local) = local