From 1c7307673bc20813a58452ad0056b505dcb20a7f Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 17 Jan 2022 17:32:58 +0100 Subject: [PATCH] Add new function textsec-mixed-numbers-p * lisp/international/textsec.el (textsec-mixed-numbers-p): New function. --- lisp/international/textsec.el | 15 +++++++++++++++ test/lisp/international/textsec-tests.el | 5 +++++ 2 files changed, 20 insertions(+) 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 -- 2.39.2