diff options
| author | Lars Ingebrigtsen | 2015-12-29 12:40:55 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2015-12-29 12:40:55 +0100 |
| commit | d181366dc39620eb0f249fc3f1d58b6199b9e44d (patch) | |
| tree | 19c2b66440a347b92f96dd5c606361cc3a56df59 | |
| parent | 5fcbeaf602e8dfcd6c7c0e9309d5bc9169f185c5 (diff) | |
| download | emacs-d181366dc39620eb0f249fc3f1d58b6199b9e44d.tar.gz emacs-d181366dc39620eb0f249fc3f1d58b6199b9e44d.zip | |
Add a new function to say whether a string is restrictive
* puny.el (puny-highly-restrictive-p): New function.
| -rw-r--r-- | lisp/net/puny.el | 20 |
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\"." | |||
| 190 | (cl-incf i))) | 190 | (cl-incf i))) |
| 191 | (buffer-string))) | 191 | (buffer-string))) |
| 192 | 192 | ||
| 193 | ;; http://www.unicode.org/reports/tr39/#Restriction_Level_Detection | ||
| 194 | |||
| 195 | (defun puny-highly-restrictive-p (string) | ||
| 196 | (let ((scripts | ||
| 197 | (seq-uniq | ||
| 198 | (seq-map (lambda (char) | ||
| 199 | (aref char-script-table char)) | ||
| 200 | string)))) | ||
| 201 | (or | ||
| 202 | ;; Every character uses the same script. | ||
| 203 | (= (length scripts) 1) | ||
| 204 | (seq-some 'identity | ||
| 205 | (mapcar (lambda (list) | ||
| 206 | (seq-every-p (lambda (script) | ||
| 207 | (memq script list)) | ||
| 208 | scripts)) | ||
| 209 | '((latin han hiragana kana) | ||
| 210 | (latin han bopomofo) | ||
| 211 | (latin han hangul))))))) | ||
| 212 | |||
| 193 | (provide 'puny) | 213 | (provide 'puny) |
| 194 | 214 | ||
| 195 | ;;; puny.el ends here | 215 | ;;; puny.el ends here |