]> git.eshelyaron.com Git - emacs.git/commitdiff
Add new function textsec-mixed-numbers-p
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 17 Jan 2022 16:32:58 +0000 (17:32 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 17 Jan 2022 16:32:58 +0000 (17:32 +0100)
* lisp/international/textsec.el (textsec-mixed-numbers-p): New
function.

lisp/international/textsec.el
test/lisp/international/textsec-tests.el

index 35da871907b662ac386ee992175c1b62acadca80..340468828cae8c85fc3acb2eccbd4656153d446f 100644 (file)
@@ -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
index 7c56229e983aaa40e5cf253cd345d3005c0e63d6..3738545e0734cc53113f0f8f8cf010d0f65c6bf3 100644 (file)
@@ -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