From: Lars Ingebrigtsen Date: Mon, 17 Jan 2022 16:32:58 +0000 (+0100) Subject: Add new function textsec-mixed-numbers-p X-Git-Tag: emacs-29.0.90~2987 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1c7307673bc20813a58452ad0056b505dcb20a7f;p=emacs.git Add new function textsec-mixed-numbers-p * lisp/international/textsec.el (textsec-mixed-numbers-p): New function. --- diff --git a/lisp/international/textsec.el b/lisp/international/textsec.el index 35da871907b..340468828ca 100644 --- a/lisp/international/textsec.el +++ b/lisp/international/textsec.el @@ -152,6 +152,21 @@ Levels are (in order of restrictiveness) `ascii-only', (t 'unrestricted)))) +(defun textsec-mixed-numbers-p (string) + "Return non-nil if there are numbers from different decimal systems in STRING." + (> (length + (seq-uniq + (textsec-scripts + (apply #'string + (seq-filter (lambda (char) + ;; We're selecting the characters that + ;; have a numeric property. + (eq (get-char-code-property char 'general-category) + 'Nd)) + string))) + #'equal)) + 1)) + (provide 'textsec) ;;; textsec.el ends here diff --git a/test/lisp/international/textsec-tests.el b/test/lisp/international/textsec-tests.el index 7c56229e983..3738545e073 100644 --- a/test/lisp/international/textsec-tests.el +++ b/test/lisp/international/textsec-tests.el @@ -81,4 +81,9 @@ (should (eq (textsec-restriction-level "Сirсlе") 'unrestricted))) +(ert-deftest test-mixed-numbers () + (should-not (textsec-mixed-numbers-p "foo")) + (should-not (textsec-mixed-numbers-p "8foo8")) + (should (textsec-mixed-numbers-p "8foo৪"))) + ;;; textsec-tests.el ends here