vcard 0.1.2 → 0.1.3
raw patch · 5 files changed
+26/−8 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- Text/VCard.hs +5/−4
- Text/VCard/Format/Directory.hs +3/−1
- Text/VCard/Query.hs +14/−2
- Text/VCard/Types.hs +3/−0
- vcard.cabal +1/−1
Text/VCard.hs view
@@ -9,10 +9,11 @@ -- additionto the mime-directory library, with the exception of -- |Text.VCard.Query|, since that library should be imported qualified, as -- many of the names clash with standard |Prelude| names.-module Text.VCard- ( module D- , module Text.VCard.Types- , module Text.VCard.Selectors ) where+--+-- To use this library, you probably want to import one of the modules in+-- |Text.VCard.Format| only, to parse and serialize vcards in specific formats.+module Text.VCard ( module D , module Text.VCard.Types , module+Text.VCard.Selectors ) where import Codec.MIME.ContentType.Text.Directory as D import Text.VCard.Types
Text/VCard/Format/Directory.hs view
@@ -4,7 +4,9 @@ -- Maintainer : mboes@tweag.net -- Stability : experimental -- Portability : non-portable-+--+-- Implements the vCard format defined in RFC 2426, based on the+-- text/directory MIME type defined in RFC 2425. module Text.VCard.Format.Directory ( module Text.VCard, readVCards, fromProperties, writeVCard ) where
Text/VCard/Query.hs view
@@ -4,7 +4,9 @@ -- Maintainer : mboes@tweag.net -- Stability : experimental -- Portability : portable-+--+-- Convenience functions to extract values in vCards and mapping over+-- these values. module Text.VCard.Query where import Text.VCard.Types@@ -14,11 +16,15 @@ import qualified Data.ByteString.Lazy.Char8.Caseless as I +-- | Analog to |Data.List.lookup|. In general an attribute may map to a number+-- of values. vCards should maintain the invariant that @forall attr, lookup+-- attr vcard /= Just []@. lookup :: I.ByteString -> VCard -> Maybe [VCardValue] lookup typ vcard = fmap (Prelude.map D.prop_value) $ Map.lookup typ (vcard_properties vcard) --- | Unsafe variant that assumes given type name maps to exactly one value in the vCard.+-- | Unsafe variant of |lookup| that assumes given type name maps to exactly+-- one value in the vCard. lookup' :: I.ByteString -> VCard -> VCardValue lookup' typ vcard = D.prop_value $ head $ fromJust $ Map.lookup typ (vcard_properties vcard)@@ -28,24 +34,30 @@ vcard{ vcard_properties = Map.insertWith merge (D.type_name (D.prop_type p)) [p] attrs } where merge [p] ps = p:ps +-- | Supports the most general filter predicates of the @filter@ family of functions. filterWithProperty :: (VProperty -> Bool) -> [VCard] -> [VCard] filterWithProperty f = Prelude.filter (not . Map.null . (Map.filter (not . null . Prelude.filter f) . vcard_properties)) +-- | A specialization of |filterWithProperty|. filterWithType :: (D.Type -> VCardValue -> Bool) -> [VCard] -> [VCard] filterWithType f = filterWithProperty (\prop -> f (D.prop_type prop) (D.prop_value prop)) +-- | Filter by property value only. filter :: (VCardValue -> Bool) -> [VCard] -> [VCard] filter f = filterWithProperty (\prop -> f (D.prop_value prop)) +-- | Supports the most general map predicates of the @map@ family of functions. mapWithProperty :: (VProperty -> VCardValue) -> [VCard] -> [VCard] mapWithProperty f = Prelude.map updateVCard where updateProp prop = prop { D.prop_value = (f prop) } updateVCard vcard = vcard { vcard_properties = Map.map (Prelude.map updateProp) (vcard_properties vcard) } +-- | A specialization of |mapWithProperty|. mapWithType :: (D.Type -> VCardValue -> VCardValue) -> [VCard] -> [VCard] mapWithType f = mapWithProperty (\prop -> f (D.prop_type prop) (D.prop_value prop)) +-- | Map by property value only. map :: (VCardValue -> VCardValue) -> [VCard] -> [VCard] map f = mapWithProperty (\prop -> f (D.prop_value prop))
Text/VCard/Types.hs view
@@ -20,6 +20,7 @@ , version_minor :: Int } deriving Show +-- | Additional value specifications in RFC 2426. data ExtraValue = Struct [[B.ByteString]] | Binary B.ByteString | PhoneNumber B.ByteString@@ -32,6 +33,8 @@ | SubVCard VCard deriving Show +-- | A |VCardValue| obeys the union of the value specifications in RFC 2425+-- and RFC 2426. type VCardValue = D.Value ExtraValue type VProperty = D.Property ExtraValue type SourceName = String
vcard.cabal view
@@ -1,5 +1,5 @@ name: vcard-version: 0.1.2+version: 0.1.3 author: Mathieu Boespflug maintainer: Mathieu Boespflug <mboes@tweag.net> homepage: http://code.haskell.org/~mboes/vcard.git