emacs-diffs
[Top][All Lists]
Advanced

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

master 1c7307673b: Add new function textsec-mixed-numbers-p


From: Lars Ingebrigtsen
Subject: master 1c7307673b: Add new function textsec-mixed-numbers-p
Date: Mon, 17 Jan 2022 11:33:13 -0500 (EST)

branch: master
commit 1c7307673bc20813a58452ad0056b505dcb20a7f
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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 35da871907..340468828c 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 7c56229e98..3738545e07 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



reply via email to

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