branch: externals/ebdb commit e78dd19203c39980516a3188844722e25348141b Author: Eric Abrahamsen <e...@ericabrahamsen.net> Commit: Eric Abrahamsen <e...@ericabrahamsen.net>
Provide an ebdb-parse method for addresses * ebdb-i18n.el (ebdb-parse): This is a base ebdb-parse method, but lives here because address parsing is only supported for internationalized EBDB. * ebdb-i18n-basic.el (ebdb-parse-i18n): Provide a base parsing method for US addresses. --- ebdb-i18n.el | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/ebdb-i18n.el b/ebdb-i18n.el index 5dc26a3..c33800f 100644 --- a/ebdb-i18n.el +++ b/ebdb-i18n.el @@ -705,33 +705,30 @@ for their symbol representations." (cl-no-method nil))) (cl-call-next-method)))) -;; This method can be used later. Probably there will never be a -;; non-i18n `ebdb-parse' method for addresses, because it's just too -;; hard to guess if you don't know the country. At some point there -;; should be an option called `ebdb-read-address-articulate': if that -;; is nil, then we should require the user to have loaded `ebdb-i18n', -;; and only international parse methods will be considered. - -;; (cl-defmethod ebdb-parse :extra "i18n" ((class (subclass ebdb-field-address)) -;; (str string) -;; &optional slots) -;; "Internationally-aware version of `ebdb-parse' for addresses." -;; (let ((cc (or (plist-get slots :country) -;; (when (string-match (regexp-opt -;; (mapcar -;; (lambda (elt) (car elt)) -;; (ebdb-i18n-countries))) -;; str) -;; (cdr-safe (assoc-string -;; (match-string 0 str) -;; (ebdb-i18n-countries) -;; )))))) -;; (or (and cc -;; (symbolp cc) -;; (condition-case nil -;; (ebdb-parse-i18n class str cc slots) -;; (cl-no-method nil))) -;; (cl-call-next-method)))) +;; This is not an :extra method, because there will never be a +;; non-i18n `ebdb-parse' method for addresses. It's just too hard to +;; guess if you don't know the country. This is only used in +;; snarfing. + +(cl-defmethod ebdb-parse ((class (subclass ebdb-field-address)) + (str string) + &optional slots) + "Internationally-aware version of `ebdb-parse' for addresses." + (let ((cc (or (plist-get slots :country) + (when (string-match (regexp-opt + (mapcar + (lambda (elt) (car elt)) + (ebdb-i18n-countries))) + str) + (cdr-safe (assoc-string + (match-string 0 str) + (ebdb-i18n-countries))))))) + (or (and cc + (symbolp cc) + (condition-case nil + (ebdb-parse-i18n class str cc slots) + (cl-no-method nil))) + (signal 'ebdb-unparseable (list str))))) (cl-defmethod ebdb-read :extra "i18n" ((class (subclass ebdb-field-phone)) &optional slots obj)