emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ebdb e6717b8 1/5: Small updates to phone number parsing


From: Eric Abrahamsen
Subject: [elpa] externals/ebdb e6717b8 1/5: Small updates to phone number parsing
Date: Fri, 3 Sep 2021 18:09:20 -0400 (EDT)

branch: externals/ebdb
commit e6717b85f93deafd1ed40364caa7553b034c1f5d
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    Small updates to phone number parsing
    
    * ebdb.el (ebdb-parse): Allow spaces and dashes in the number part;
    remove everything but digits afterwards.
    * ebdb-test.el (ebdb-parse-phone): Add test.
---
 ebdb-test.el | 11 +++++++++++
 ebdb.el      | 10 +++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/ebdb-test.el b/ebdb-test.el
index 15cdd51..390d232 100644
--- a/ebdb-test.el
+++ b/ebdb-test.el
@@ -379,6 +379,17 @@ If it doesn't exist, raise `ebdb-related-unfound'."
            'surname)
           "Day-Lewis")))
 
+(ert-deftest ebdb-parse-phone ()
+  "Parse various strings as phone fields."
+  (let ((parsed (ebdb-parse 'ebdb-field-phone "+1 (226) 697-5852 ext. 22"))
+       (parsed2 (ebdb-parse 'ebdb-field-phone "+1 (226) 697 58 52X22")))
+   (should (eql (slot-value parsed 'country-code) 1))
+   (should (eql (slot-value parsed 'area-code) 226))
+   (should (equal (slot-value parsed 'number) "6975852"))
+   (should (eql (slot-value parsed 'extension) 22))
+   (should (equal (slot-value parsed2 'number) "6975852"))
+   (should (eql (slot-value parsed2 'extension) 22))))
+
 ;; Snarf testing.
 
 (ert-deftest ebdb-snarf-mail-and-name ()
diff --git a/ebdb.el b/ebdb.el
index 42cab93..c6229c3 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -2027,11 +2027,15 @@ The result looks like this:
       ;; number, partially because if it's too long Emacs turns it
       ;; into a float, which is a pain in the ass.
       (when (and (< (point) (point-max))
-                (re-search-forward (format "\\([^[:blank:]]+\\)\\(%s\\)?"
-                                           ext-regexp)))
+                (re-search-forward
+                 (format "\\([-[:digit:][:blank:]]+\\)\\(%s\\)?[[:blank:]]*\\'"
+                         ext-regexp)))
        (unless (plist-member slots :number)
          (setq slots
-               (plist-put slots :number (match-string 1))))
+               (plist-put
+                slots :number
+                (replace-regexp-in-string
+                 "[^[:digit:]]" "" (match-string 1)))))
        (unless (or (plist-member slots :extension)
                    (null (match-string 2)))
          (setq slots



reply via email to

[Prev in Thread] Current Thread [Next in Thread]