Skip to content

Commit

Permalink
pyim-cstring-substrings* -> pyim-cstring--substrings*
Browse files Browse the repository at this point in the history
  • Loading branch information
tumashu committed Jun 24, 2022
1 parent d5d98bd commit 20d9fee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyim-cstring-utils.el
Expand Up @@ -61,7 +61,7 @@ CHINESE-STRING 分词,得到一个词条 alist,这个 alist 的元素都是
(pyim-dcache-init-variables)

(let (result)
(dolist (string-list (pyim-cstring-substrings chinese-string max-word-length))
(dolist (string-list (pyim-cstring--substrings chinese-string max-word-length))
(let ((pinyin-list (pyim-cstring-to-pinyin (car string-list) nil "-" t)))
(dolist (pinyin pinyin-list)
(let ((words (pyim-dcache-get pinyin '(code2word)))) ; 忽略个人词库可以提高速度
Expand Down
14 changes: 7 additions & 7 deletions pyim-cstring.el
Expand Up @@ -55,27 +55,27 @@
(cl-mapcar #'char-to-string string)
(list string)))))

(defun pyim-cstring-substrings (cstring &optional max-length number)
(defun pyim-cstring--substrings (cstring &optional max-length number)
"找出 CSTRING 中所有长度不超过 MAX-LENGTH 的子字符串,生成一个 alist。
这个 alist 中的每个元素为:(子字符串 开始位置 结束位置), 参数
NUMBER 用于递归,表示子字符串在 CSTRING 中的位置。"
(let ((number (or number 0)))
(cond
((= (length cstring) 0) nil)
(t (append (pyim-cstring-substrings-1 cstring max-length number)
(pyim-cstring-substrings (substring cstring 1)
max-length (1+ number)))))))
(t (append (pyim-cstring--substrings-1 cstring max-length number)
(pyim-cstring--substrings (substring cstring 1)
max-length (1+ number)))))))

(defun pyim-cstring-substrings-1 (cstring max-length number)
"`pyim-cstring-substrings' 的内部函数。"
(defun pyim-cstring--substrings-1 (cstring max-length number)
"`pyim-cstring--substrings' 的内部函数。"
(cond
((< (length cstring) 2) nil)
(t (append
(let ((length (length cstring)))
(when (<= length (or max-length 6))
(list (list cstring number (+ number length)))))
(pyim-cstring-substrings-1
(pyim-cstring--substrings-1
(substring cstring 0 -1)
max-length number)))))

Expand Down
8 changes: 4 additions & 4 deletions tests/pyim-tests.el
Expand Up @@ -726,22 +726,22 @@
(should (equal (pyim-cstring--partition "hello" t)
'("hello"))))

(ert-deftest pyim-tests-pyim-cstring-substrings ()
(should (equal (pyim-cstring-substrings "我爱北京")
(ert-deftest pyim-tests-pyim-cstring--substrings ()
(should (equal (pyim-cstring--substrings "我爱北京")
'(("我爱北京" 0 4)
("我爱北" 0 3)
("我爱" 0 2)
("爱北京" 1 4)
("爱北" 1 3)
("北京" 2 4))))
(should (equal (pyim-cstring-substrings "我爱北京" 3)
(should (equal (pyim-cstring--substrings "我爱北京" 3)
'(("我爱北" 0 3)
("我爱" 0 2)
("爱北京" 1 4)
("爱北" 1 3)
("北京" 2 4))))
(let* ((str "我爱北京")
(alist (pyim-cstring-substrings "我爱北京" 2))
(alist (pyim-cstring--substrings "我爱北京" 2))
(key (car (nth 1 alist)))
(pos (cdr (nth 1 alist))))
(should (equal (substring str (car pos) (cadr pos)) key))))
Expand Down

0 comments on commit 20d9fee

Please sign in to comment.