bbdb 0.4 → 0.5
raw patch · 3 files changed
+49/−50 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Database.BBDB: address :: BBDB -> Maybe [Address]
- Database.BBDB: aka :: BBDB -> Maybe [String]
- Database.BBDB: city :: Address -> Maybe String
- Database.BBDB: company :: BBDB -> Maybe String
- Database.BBDB: country :: Address -> Maybe String
- Database.BBDB: firstName :: BBDB -> Maybe String
- Database.BBDB: instance Eq Address
- Database.BBDB: instance Eq BBDB
- Database.BBDB: instance Eq BBDBFile
- Database.BBDB: instance Eq Note
- Database.BBDB: instance Eq Phone
- Database.BBDB: instance LispAble (Maybe Note)
- Database.BBDB: instance LispAble (Maybe String)
- Database.BBDB: instance LispAble (Maybe [Address])
- Database.BBDB: instance LispAble (Maybe [Phone])
- Database.BBDB: instance LispAble (Maybe [String])
- Database.BBDB: instance LispAble Address
- Database.BBDB: instance LispAble Alist
- Database.BBDB: instance LispAble BBDB
- Database.BBDB: instance LispAble BBDBFile
- Database.BBDB: instance LispAble Note
- Database.BBDB: instance LispAble Phone
- Database.BBDB: instance LispAble String
- Database.BBDB: instance LispAble [BBDBFile]
- Database.BBDB: instance Ord Address
- Database.BBDB: instance Ord BBDB
- Database.BBDB: instance Ord BBDBFile
- Database.BBDB: instance Ord Note
- Database.BBDB: instance Ord Phone
- Database.BBDB: instance Show Address
- Database.BBDB: instance Show BBDB
- Database.BBDB: instance Show BBDBFile
- Database.BBDB: instance Show Note
- Database.BBDB: instance Show Phone
- Database.BBDB: lastName :: BBDB -> Maybe String
- Database.BBDB: location :: Address -> Location
- Database.BBDB: net :: BBDB -> Maybe [String]
- Database.BBDB: notes :: BBDB -> Maybe Note
- Database.BBDB: phone :: BBDB -> Maybe [Phone]
- Database.BBDB: state :: Address -> Maybe String
- Database.BBDB: streets :: Address -> Maybe [String]
- Database.BBDB: unnote :: Note -> [Alist]
- Database.BBDB: zipcode :: Address -> Maybe String
+ Database.BBDB: [address] :: BBDB -> Maybe [Address]
+ Database.BBDB: [affix] :: BBDB -> Maybe [String]
+ Database.BBDB: [aka] :: BBDB -> Maybe [String]
+ Database.BBDB: [city] :: Address -> Maybe String
+ Database.BBDB: [company] :: BBDB -> Maybe [String]
+ Database.BBDB: [country] :: Address -> Maybe String
+ Database.BBDB: [firstName] :: BBDB -> Maybe String
+ Database.BBDB: [lastName] :: BBDB -> Maybe String
+ Database.BBDB: [location] :: Address -> Location
+ Database.BBDB: [net] :: BBDB -> Maybe [String]
+ Database.BBDB: [notes] :: BBDB -> Maybe Note
+ Database.BBDB: [phone] :: BBDB -> Maybe [Phone]
+ Database.BBDB: [state] :: Address -> Maybe String
+ Database.BBDB: [streets] :: Address -> Maybe [String]
+ Database.BBDB: [unnote] :: Note -> [Alist]
+ Database.BBDB: [zipcode] :: Address -> Maybe String
+ Database.BBDB: instance Database.BBDB.LispAble (GHC.Base.Maybe Database.BBDB.Note)
+ Database.BBDB: instance Database.BBDB.LispAble (GHC.Base.Maybe GHC.Base.String)
+ Database.BBDB: instance Database.BBDB.LispAble (GHC.Base.Maybe [Database.BBDB.Address])
+ Database.BBDB: instance Database.BBDB.LispAble (GHC.Base.Maybe [Database.BBDB.Phone])
+ Database.BBDB: instance Database.BBDB.LispAble (GHC.Base.Maybe [GHC.Base.String])
+ Database.BBDB: instance Database.BBDB.LispAble Database.BBDB.Address
+ Database.BBDB: instance Database.BBDB.LispAble Database.BBDB.Alist
+ Database.BBDB: instance Database.BBDB.LispAble Database.BBDB.BBDB
+ Database.BBDB: instance Database.BBDB.LispAble Database.BBDB.BBDBFile
+ Database.BBDB: instance Database.BBDB.LispAble Database.BBDB.Note
+ Database.BBDB: instance Database.BBDB.LispAble Database.BBDB.Phone
+ Database.BBDB: instance Database.BBDB.LispAble GHC.Base.String
+ Database.BBDB: instance Database.BBDB.LispAble [Database.BBDB.BBDBFile]
+ Database.BBDB: instance GHC.Classes.Eq Database.BBDB.Address
+ Database.BBDB: instance GHC.Classes.Eq Database.BBDB.BBDB
+ Database.BBDB: instance GHC.Classes.Eq Database.BBDB.BBDBFile
+ Database.BBDB: instance GHC.Classes.Eq Database.BBDB.Note
+ Database.BBDB: instance GHC.Classes.Eq Database.BBDB.Phone
+ Database.BBDB: instance GHC.Classes.Ord Database.BBDB.Address
+ Database.BBDB: instance GHC.Classes.Ord Database.BBDB.BBDB
+ Database.BBDB: instance GHC.Classes.Ord Database.BBDB.BBDBFile
+ Database.BBDB: instance GHC.Classes.Ord Database.BBDB.Note
+ Database.BBDB: instance GHC.Classes.Ord Database.BBDB.Phone
+ Database.BBDB: instance GHC.Show.Show Database.BBDB.Address
+ Database.BBDB: instance GHC.Show.Show Database.BBDB.BBDB
+ Database.BBDB: instance GHC.Show.Show Database.BBDB.BBDBFile
+ Database.BBDB: instance GHC.Show.Show Database.BBDB.Note
+ Database.BBDB: instance GHC.Show.Show Database.BBDB.Phone
- Database.BBDB: BBDB :: Maybe String -> Maybe String -> Maybe [String] -> Maybe String -> Maybe [Phone] -> Maybe [Address] -> Maybe [String] -> Maybe Note -> BBDB
+ Database.BBDB: BBDB :: Maybe String -> Maybe String -> Maybe [String] -> Maybe [String] -> Maybe [String] -> Maybe [Phone] -> Maybe [Address] -> Maybe [String] -> Maybe Note -> BBDB
Files
- bbdb.cabal +2/−2
- changelog.md +10/−0
- src/Database/BBDB.hs +37/−48
bbdb.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented.-Version: 0.4+Version: 0.5 -- A short (one-line) description of the package. Synopsis: Ability to read, write, and examine BBDB files@@ -45,7 +45,7 @@ -- Extra files to be distributed with the package, such as examples or -- a README.--- Extra-source-files: +Extra-source-files: changelog.md -- Constraint on the version of Cabal needed to build this package. Cabal-version: >=1.4
+ changelog.md view
@@ -0,0 +1,10 @@+Changes for Database/BBDB+=========================++From 0.4 -> 0.5+---------------++The BBDB file format changed. The current version of the format+is 7. Once field, called *Affixes* was added, and now the extension+in a US phone field is required.+
src/Database/BBDB.hs view
@@ -1,5 +1,4 @@-{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, PackageImports #-}-+{-# LANGUAGE FlexibleInstances #-} -- | -- This module can read and write BBDB files, and provides a few handy -- functions for getting at fields inside of BBDB data.@@ -21,8 +20,9 @@ -- -- > ["Henry" The first name - a string -- > "Laxen" The last name - a string--- > ("Henry, Enrique") Also Known As - comma separated list--- > "Elegant Solutions" Business name - a string+-- > nil Affixes - a comma separated list+-- > ("Henry, Enrique") Also Known As - a comma separated list+-- > ("Elegant Solutions") Organizations- a comma separated list -- > ( -- > ["reno" 775 624 1851 0] Phone number field - US style -- > ["chapala" "011-52-376-765-3181"] Phone number field - International style@@ -51,7 +51,7 @@ -- > ] -- -- Inside the .bbdb file, this looks like:--- \[\"Henry\" \"Laxen\" (\"Henry, Enrique\") \"Elegant Solutions\" +-- \[\"Henry\" \"Laxen\" nil (\"Henry, Enrique\") (\"Elegant Solutions\") -- (\[\"reno\" 775 624 1851 0] \[\"chapala\" \"011-52-376-765-3181\"]) -- (\[\"mailing\" (\"10580 N. McCarran Blvd.\" -- \"#115-396\") \"Reno\" \"Nevada\" \"89503\" \"USA\"] @@ -66,7 +66,8 @@ -- -- > BBDBEntry -- > (BBDB{firstName = Just "Henry", lastName = Just "Laxen",--- > aka = Just ["Henry, Enrique"], company = Just "Elegant Solutions",+-- > affix = Nothing+-- > aka = Just ["Henry, Enrique"], company = Just ["Elegant Solutions"], -- > phone = -- > Just -- > [USStyle "reno" ["775", "624", "1851", "0"],@@ -98,7 +99,7 @@ Street, Symbol, Address(..), - Alist(..), + Alist, Note(..), Phone(..), BBDB(..), @@ -120,13 +121,11 @@ import Text.Parsec.Char import Text.Parsec.String (Parser) -- type Parser = Parsec String ()-import Data.Char -- (chr)-import "mtl" Control.Monad.Identity hiding (join) import Text.Parsec hiding ((<|>)) import Control.Applicative hiding (many) import Data.Maybe-import Data.List +doubleQuoteChar :: Char doubleQuoteChar = '"' betweenParens :: Parser a -> Parser a@@ -184,10 +183,10 @@ -- | Given an Alist, return the key key :: (x,y) -> x-key (x,y) = x+key (x,_) = x -- | Given an Alist, return the value value :: (x,y) -> y-value (x,y) = y+value (_,y) = y -- | The Note field of a BBDB record is just a list of associations. -- If you don\'t provide a your own key, the BBDB will use the word \"note\"@@ -206,9 +205,10 @@ -- | aka = Also Known As. Sometimes the same email address can match -- several users, so BBDB gives you the option of remembering -- different names for the same address+ affix :: Maybe [String], aka :: Maybe [String], -- | The company if any - company :: Maybe String,+ company :: Maybe [String], -- | A list of phone numbers, either in US Style or International Style phone :: Maybe [Phone], -- | A list of addresses, keyed by location@@ -221,7 +221,8 @@ } deriving (Eq, Ord, Show) -bbdbDefault = BBDB Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing+bbdbDefault :: BBDB+bbdbDefault = BBDB Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing -- | At the beginning of a BBDB file are a variable number of comments, which -- specify the encoding type and the version. We just ignore them.@@ -236,6 +237,7 @@ nil :: Parser (Maybe a) nil = string "nil" >> return Nothing +strings :: Parser [String] strings = betweenParens (sepBy quotedString space) @@ -321,9 +323,11 @@ space lastName <- stringOrNil space+ affix <- stringsOrNil+ space aka <- stringsOrNil space- company <- stringOrNil+ company <- stringsOrNil space phoneS <- phonesParser space@@ -335,15 +339,7 @@ space string "nil" char ']'- return $ BBDB firstName lastName aka company phoneS addresseS net noteS--{--bEntry :: Parser BBDB -bEntry = BBDB <$>- stringOrNil <*> stringOrNil <*> stringsOrNil <*> stringOrNil <*>- phonesParser <*> addressesParser <*> stringsOrNil <*> (notesParser <*- string "nil]")--}+ return $ BBDB firstName lastName affix aka company phoneS addresseS net noteS -- | The Parser for a BBDB file, as it is written on disk. If you@@ -374,22 +370,17 @@ justEntries :: [BBDBFile] -> [BBDB] justEntries = mapMaybe justEntry -join :: [a] -> [[a]] -> [a]-join delim l = concat (intersperse delim l)- -- | surround a string with the given two characters surroundWith :: a -> a -> [a] -> [a]-surroundWith before after string = before : string ++ [after]+surroundWith before after str = before : str ++ [after] -- | convert a Haskell string to a string that Lisp likes+escapeLisp :: String -> String escapeLisp [] = [] escapeLisp (c:cs) = case c of '"' -> '\\' : '"' : escapeLisp cs--- '\\' -> '\\' : '\\' : escapeLisp cs- otherwise -> c : escapeLisp cs- -- let x = if isAscii c then [c] else '\\' : c : []- -- in x ++ escapeLisp cs+ _ -> c : escapeLisp cs -- | LispAble is how we convert from our internal representation of a -- BBDB record, to one that will make Lisp and Emacs happy. (Sans bugs)@@ -415,23 +406,23 @@ instance LispAble (Maybe [String]) where asLisp Nothing = "nil"- asLisp (Just x) = surroundWith '(' ')' . join " " .+ asLisp (Just x) = surroundWith '(' ')' . unwords . map (surroundWith '"' '"' . asLisp) $ x instance LispAble Phone where- asLisp (USStyle location numbers) =- surroundWith '[' ']' $ surroundWith '"' '"' location ++ " " ++ - join " " numbers+ asLisp (USStyle loc numbers) =+ surroundWith '[' ']' $ surroundWith '"' '"' loc ++ " " ++ + unwords numbers asLisp (InternationalStyle location numbers) = surroundWith '[' ']' $ surroundWith '"' '"' location ++ " " ++ surroundWith '"' '"' numbers instance LispAble (Maybe [Phone]) where asLisp Nothing = "nil"- asLisp (Just x) = surroundWith '(' ')' . join " " . map asLisp $ x+ asLisp (Just x) = surroundWith '(' ')' . unwords . map asLisp $ x instance LispAble Address where- asLisp x = surroundWith '[' ']' $ join " " + asLisp x = surroundWith '[' ']' $ unwords [asLisp $ Just (location x), asLisp (streets x), asLisp (city x),@@ -441,7 +432,7 @@ instance LispAble (Maybe [Address]) where asLisp Nothing = "nil"- asLisp (Just x) = surroundWith '(' ')' . join " " .+ asLisp (Just x) = surroundWith '(' ')' . unwords . map asLisp $ x instance LispAble Alist where@@ -449,16 +440,16 @@ key x ++ " . " ++ asLisp (Just (value x)) instance LispAble Note where- asLisp (Note x) = surroundWith '(' ')' . join " " .+ asLisp (Note x) = surroundWith '(' ')' . unwords . map asLisp $ x instance LispAble (Maybe Note) where asLisp Nothing = "nil"- asLisp (Just x) = surroundWith '(' ')' . join " " . + asLisp (Just x) = surroundWith '(' ')' . unwords . map asLisp $ unnote x instance LispAble BBDB where- asLisp x = surroundWith '[' ']' $ join " " + asLisp x = surroundWith '[' ']' $ unwords [asLisp (firstName x), asLisp (lastName x), asLisp (aka x),@@ -482,7 +473,6 @@ parseBBDB :: String -> Either ParseError [BBDBFile] parseBBDB = parse bbdbFileParse "bbdb" - -- | read the given file and call error if the parse failed, -- otherwise return the entire file as a list of BBDBFile records. readBBDB :: String -> IO [BBDBFile]@@ -491,7 +481,6 @@ let ls = parseBBDB b return . either (error . show) id $ ls - -- | Notes inside a BBDB record are awkward to get at. This helper -- function digs into the record and applies a function to each -- Alist element of the record. It returns true if it any of the@@ -505,7 +494,7 @@ wantNote :: (Alist -> Bool) -> BBDB -> Bool wantNote cond bbdb = maybe False alistTest (notes bbdb) where- alistTest = any id . map cond . unnote+ alistTest = any cond . unnote -- | Lookup the value whose key is the given string. If found returns -- Just the value, otherwise Nothing For example:@@ -534,7 +523,7 @@ -- field of a BBDB file and write the result -- out as a new bbdb file. mapBBDB :: (BBDB -> BBDB) -> [BBDBFile] -> [BBDBFile]-mapBBDB f bbdbf = map g bbdbf+mapBBDB f = map g where g (BBDBComment x) = BBDBComment x g (BBDBEntry x) = BBDBEntry (f x)@@ -562,9 +551,9 @@ -- print the name and all addresses of anyone in the BBDB file -- who live in Reno. filterBBDB :: (BBDB -> Bool) -> [BBDBFile] -> [BBDBFile]-filterBBDB f bbdbf = filter g bbdbf+filterBBDB f = filter g where- g (BBDBComment x) = True+ g (BBDBComment _) = False g (BBDBEntry x) = f x