aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/net
diff options
context:
space:
mode:
authorLars Ingebrigtsen2015-12-28 02:55:52 +0100
committerLars Ingebrigtsen2015-12-28 02:55:52 +0100
commitbd892f033229d13a7f84e45906c070c052d4b1ae (patch)
tree4f87ac139ec5c0f12853725e38f130036a3d3592 /lisp/net
parent6a15c60d348c2652cca15b723ff72f8a6c53bb08 (diff)
downloademacs-bd892f033229d13a7f84e45906c070c052d4b1ae.tar.gz
emacs-bd892f033229d13a7f84e45906c070c052d4b1ae.zip
Clean up the code slightly
Diffstat (limited to 'lisp/net')
-rw-r--r--lisp/net/idna.el63
1 files changed, 29 insertions, 34 deletions
diff --git a/lisp/net/idna.el b/lisp/net/idna.el
index 24a771b0bb8..f34fb9c490a 100644
--- a/lisp/net/idna.el
+++ b/lisp/net/idna.el
@@ -27,22 +27,13 @@
27 27
28;;; Code: 28;;; Code:
29 29
30(require 'seq)
31
30(defun idna-encode-string (string) 32(defun idna-encode-string (string)
31 (cl-destructuring-bind (ascii complex) 33 (let ((ascii (seq-filter (lambda (char)
32 (cl-loop for i from 0 34 (< char 128))
33 for char across string 35 string)))
34 when (< char 128) 36 (concat "xn--" ascii "-" (idna-encode-complex (length ascii) string))))
35 collect char into ascii
36 else
37 collect (cons i char) into complex
38 finally (return (list ascii complex)))
39 (concat (mapconcat 'string ascii "")
40 "-"
41 (idna-encode-complex (length ascii)
42 (sort complex
43 (lambda (e1 e2)
44 (< (cdr e1) (cdr e2))))
45 string))))
46 37
47(defconst idna-initial-n 128) 38(defconst idna-initial-n 128)
48(defconst idna-initial-bias 72) 39(defconst idna-initial-bias 72)
@@ -53,13 +44,15 @@
53(defconst idna-skew 28) 44(defconst idna-skew 28)
54 45
55(defun idna-decode-digit (cp) 46(defun idna-decode-digit (cp)
56 (if (< (- cp 48) 10) 47 (cond
57 (- cp 22) 48 ((< (- cp 48) 10)
58 (if (< (- cp 65) 26) 49 (- cp 22))
59 (- cp 65) 50 ((< (- cp 65) 26)
60 (if (< (- cp 97) 26) 51 (- cp 65))
61 (- cp 97) 52 ((< (- cp 97) 26)
62 idna-base)))) 53 (- cp 97))
54 (t
55 idna-base)))
63 56
64;; 0-25 a-z 57;; 0-25 a-z
65;; 26-36 0-9 58;; 26-36 0-9
@@ -74,20 +67,20 @@
74 (/ delta 2))) 67 (/ delta 2)))
75 (k 0)) 68 (k 0))
76 (setq delta (+ delta (/ delta num-points))) 69 (setq delta (+ delta (/ delta num-points)))
77 (cl-loop while (> delta (/ (* (- idna-base idna-tmin) 70 (while (> delta (/ (* (- idna-base idna-tmin)
78 idna-tmax) 71 idna-tmax)
79 2)) 72 2))
80 do (setq delta (/ delta (- idna-base idna-tmin)) 73 (setq delta (/ delta (- idna-base idna-tmin))
81 k (+ k idna-base))) 74 k (+ k idna-base)))
82 (+ k (/ (* (1+ (- idna-base idna-tmin)) delta) 75 (+ k (/ (* (1+ (- idna-base idna-tmin)) delta)
83 (+ delta idna-skew))))) 76 (+ delta idna-skew)))))
84 77
85(defun idna-encode-complex (insertion-points complex string) 78(defun idna-encode-complex (insertion-points string)
86 (let ((n idna-initial-n) 79 (let ((n idna-initial-n)
87 (delta 0) 80 (delta 0)
88 (bias idna-initial-bias) 81 (bias idna-initial-bias)
89 (h insertion-points) 82 (h insertion-points)
90 result m) 83 result m ijv q)
91 (while (< h (length string)) 84 (while (< h (length string))
92 (setq ijv (cl-loop for char across string 85 (setq ijv (cl-loop for char across string
93 when (>= char n) 86 when (>= char n)
@@ -102,11 +95,13 @@
102 do (progn 95 do (progn
103 (setq q delta) 96 (setq q delta)
104 (cl-loop with k = idna-base 97 (cl-loop with k = idna-base
105 for t1 = (if (<= k bias) 98 for t1 = (cond
106 idna-tmin 99 ((<= k bias)
107 (if (>= k (+ bias idna-tmax)) 100 idna-tmin)
108 idna-tmax 101 ((>= k (+ bias idna-tmax))
109 (- k bias))) 102 idna-tmax)
103 (t
104 (- k bias)))
110 while (>= q t1) 105 while (>= q t1)
111 do (push (idna-encode-digit 106 do (push (idna-encode-digit
112 (+ t1 (mod (- q t1) 107 (+ t1 (mod (- q t1)