]> git.eshelyaron.com Git - emacs.git/commitdiff
Add a new function to say whether a string is restrictive
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 29 Dec 2015 11:40:55 +0000 (12:40 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 29 Dec 2015 11:40:55 +0000 (12:40 +0100)
* puny.el (puny-highly-restrictive-p): New function.

lisp/net/puny.el

index d96c6c22196ae04700545432b4a65ce4de4f2ba6..08da51b587fe110ccd1f0e7569e37d71e8f99f85 100644 (file)
@@ -190,6 +190,26 @@ For instance \"xn--bcher-kva\" => \"bücher\"."
         (cl-incf i)))
     (buffer-string)))
 
+;; http://www.unicode.org/reports/tr39/#Restriction_Level_Detection
+
+(defun puny-highly-restrictive-p (string)
+  (let ((scripts
+         (seq-uniq
+          (seq-map (lambda (char)
+                     (aref char-script-table char))
+                   string))))
+    (or
+     ;; Every character uses the same script.
+     (= (length scripts) 1)
+     (seq-some 'identity
+               (mapcar (lambda (list)
+                         (seq-every-p (lambda (script)
+                                        (memq script list))
+                                      scripts))
+                       '((latin han hiragana kana)
+                         (latin han bopomofo)
+                         (latin han hangul)))))))
+
 (provide 'puny)
 
 ;;; puny.el ends here