[Top][All Lists]

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

[elpa] externals/ebdb d88f6a9 08/11: New function ebdb-parse-search-stri

From: Eric Abrahamsen
Subject: [elpa] externals/ebdb d88f6a9 08/11: New function ebdb-parse-search-string
Date: Wed, 19 Dec 2018 13:47:55 -0500 (EST)

branch: externals/ebdb
commit d88f6a9cf85a3ce6bc73cb6bb5f67dadfe0be572
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>

    New function ebdb-parse-search-string
    * ebdb.el (ebdb-parse-search-string): New function that parses a
      string containing multiple field values to search against into a
      list of search cells. Don't actually do anything with this yet.
    At some point, when we support AND searches, this will be handy.
 ebdb.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/ebdb.el b/ebdb.el
index 64ab609..0d5af8f 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -5142,6 +5142,37 @@ additionally prompt to save each database individually."
 (defvar ebdb-search-invert nil
   "Bind to t to invert the result of `ebdb-search'.")
+(defun ebdb-parse-search-string (str)
+  "Parse STR as a search on multiple fields.
+STR should contain some number of <key>:<value> pairs, where key
+is the name of a field class, or a field class shortcut such as
+\"name\" or \"mail\", and the value is an arbitrary string value
+to search on.
+Values containing spaces should be enclosed in double quotes.
+Returns a list of (field value) pairs suitable for searching."
+  (let (parsed)
+    (with-temp-buffer
+      (insert str)
+      (goto-char (point-min))
+      (skip-syntax-forward " ")
+      (while (re-search-forward
+             (point-max) t)
+       (let* ((key-string (match-string 1))
+              (sym (or (and (string-match-p "ebdb-field-" key-string)
+                            (intern-soft key-string))
+                       (intern-soft (format "ebdb-field-%s" key-string)))))
+         (if (and (class-p sym)
+                  (child-of-class-p sym 'ebdb-field))
+             (push (list sym
+                         (match-string 2))
+                   parsed)
+           (signal 'ebdb-unparseable
+                   (list "Invalid search key" key-string))))))
+    parsed))
 ;; Char folding: a simplified version of what happens in char-fold.el.
 (defconst ebdb-char-fold-table

reply via email to

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