summaryrefslogtreecommitdiff
path: root/lisp/net/puny.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2015-12-29 12:40:55 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2015-12-29 12:40:55 +0100
commitd181366dc39620eb0f249fc3f1d58b6199b9e44d (patch)
tree19c2b66440a347b92f96dd5c606361cc3a56df59 /lisp/net/puny.el
parent5fcbeaf602e8dfcd6c7c0e9309d5bc9169f185c5 (diff)
downloademacs-d181366dc39620eb0f249fc3f1d58b6199b9e44d.tar.gz
emacs-d181366dc39620eb0f249fc3f1d58b6199b9e44d.tar.bz2
emacs-d181366dc39620eb0f249fc3f1d58b6199b9e44d.zip
Add a new function to say whether a string is restrictive
* puny.el (puny-highly-restrictive-p): New function.
Diffstat (limited to 'lisp/net/puny.el')
-rw-r--r--lisp/net/puny.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/lisp/net/puny.el b/lisp/net/puny.el
index d96c6c22196..08da51b587f 100644
--- a/lisp/net/puny.el
+++ b/lisp/net/puny.el
@@ -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