[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 4a92386 2/2: * pyim-dcache.el (pyim-dcache-code-sp
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 4a92386 2/2: * pyim-dcache.el (pyim-dcache-code-split): re-add. |
Date: |
Tue, 14 Dec 2021 10:57:30 -0500 (EST) |
branch: externals/pyim
commit 4a92386bc2e9b4afcb07aa6d12298faffd794ee5
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
* pyim-dcache.el (pyim-dcache-code-split): re-add.
---
pyim-dcache.el | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/pyim-dcache.el b/pyim-dcache.el
index 0a43521..d34b541 100644
--- a/pyim-dcache.el
+++ b/pyim-dcache.el
@@ -272,6 +272,25 @@ code 对应的中文词条了."
`(,@(pyim-dcache-call-api 'get code from)
,@(pyim-pymap-py2cchar-get code t t)))
+;; ** 分割 code
+(defun pyim-dcache-code-split (code)
+ "将 CODE 分成 code-prefix 和 rest code."
+ (cond
+ ;; 处理 nil
+ ((not code) nil)
+ ;; 兼容性代码:旧版本的 pyim 使用一个标点符号作为 code-prefix
+ ((pyim-string-match-p "^[[:punct:]]" code)
+ (list (substring code 0 1) (substring code 1)))
+ ;; 拼音输入法不使用 code-prefix, 并且包含 -
+ ((pyim-string-match-p "-" code)
+ (list "" code))
+ ((not (pyim-string-match-p "[[:punct:]]" code))
+ (list "" code))
+ ;; 新 code-prefix 使用类似 "wubi/" 的格式。
+ (t (let ((x (split-string code "/")))
+ (list (concat (nth 0 x) "/")
+ (nth 1 x))))))
+
;; * Footer
(provide 'pyim-dcache)