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

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

[elpa] externals/pyim 63d2399cb8 4/4: Refactor pyim-cregexp-create-crege


From: ELPA Syncer
Subject: [elpa] externals/pyim 63d2399cb8 4/4: Refactor pyim-cregexp-create-cregexp-from-string.
Date: Wed, 22 Jun 2022 02:57:55 -0400 (EDT)

branch: externals/pyim
commit 63d2399cb8a92e84448b5cd6ba0c940fa767c41d
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    Refactor pyim-cregexp-create-cregexp-from-string.
---
 pyim-cregexp.el | 71 ++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 31 deletions(-)

diff --git a/pyim-cregexp.el b/pyim-cregexp.el
index f54afa12f6..08755dd419 100644
--- a/pyim-cregexp.el
+++ b/pyim-cregexp.el
@@ -149,39 +149,48 @@ regexp, 所以搜索单字的时候一般可以搜到生僻字,但搜索句子
     (_ (funcall fn rx-form))))
 
 (defun pyim-cregexp-create-cregexp-from-string
-    (str scheme &optional char-level-num chinese-only)
-  (let* ((num (pyim-cregexp-char-level-num char-level-num))
-         (sep "#####&&&&#####")
-         (lst (remove "" (split-string
-                          (replace-regexp-in-string
-                           "\\([a-z]+'*\\)" (concat sep "\\1" sep) str)
-                          sep))))
+    (string scheme &optional char-level-num chinese-only)
+  (let* ((char-level-num (pyim-cregexp-char-level-num char-level-num))
+         (string-list (pyim-cregexp-split-string string)))
     ;; 确保 pyim 词库加载
     (pyim-dcache-init-variables)
-    (mapconcat
-     (lambda (string)
-       (if (or (pyim-string-match-p "[^a-z']+" string)
-               (equal string ""))
-           string
-         (let* ((string1 (replace-regexp-in-string "'" "" string))
-                (imobjs (pyim-imobjs-create string1 scheme))
-                (regexp-list
-                 (mapcar (lambda (imobj)
-                           (pyim-cregexp-create-from-imobj imobj scheme nil 
nil nil num))
-                         imobjs))
-                (regexp
-                 (when regexp-list
-                   (string-join (delq nil regexp-list) "\\|")))
-                (regexp
-                 (if chinese-only
-                     regexp
-                   (if (> (length regexp) 0)
-                       (if (equal string string1)
-                           (concat string "\\|" regexp)
-                         (concat string "\\|" string1 "\\|" regexp))
-                     string))))
-           (format "\\(?:%s\\)" regexp))))
-     lst "")))
+    (pyim-cregexp-create-cregexp-from-string-list
+     string-list scheme char-level-num chinese-only)))
+
+(defun pyim-cregexp-split-string (string)
+  (let ((sep "#####&&&&#####"))
+    (remove "" (split-string
+                (replace-regexp-in-string
+                 "\\([a-z]+'*\\)" (concat sep "\\1" sep) string)
+                sep))))
+
+(defun pyim-cregexp-create-cregexp-from-string-list
+    (string-list scheme &optional char-level-num chinese-only)
+  (mapconcat
+   (lambda (string)
+     (if (or (pyim-string-match-p "[^a-z']+" string)
+             (equal string ""))
+         string
+       (let* ((string1 (replace-regexp-in-string "'" "" string))
+              (imobjs (pyim-imobjs-create string1 scheme))
+              (regexp-list
+               (mapcar (lambda (imobj)
+                         (pyim-cregexp-create-from-imobj
+                          imobj scheme nil nil nil char-level-num))
+                       imobjs))
+              (regexp
+               (when regexp-list
+                 (string-join (delq nil regexp-list) "\\|")))
+              (regexp
+               (if chinese-only
+                   regexp
+                 (if (> (length regexp) 0)
+                     (if (equal string string1)
+                         (concat string "\\|" regexp)
+                       (concat string "\\|" string1 "\\|" regexp))
+                   string))))
+         (format "\\(?:%s\\)" regexp))))
+   string-list ""))
 
 (cl-defgeneric pyim-cregexp-create-from-imobj
     (imobj _scheme &optional match-beginning



reply via email to

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