changeset 72196:5b336ff592bb

(url-hexify-string): Rewrite.
author Thien-Thi Nguyen <ttn@gnuvola.org>
date Sun, 30 Jul 2006 20:19:36 +0000
parents c348014e6508
children 041a1fa70b9e
files lisp/url/url-util.el
diffstat 1 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/url/url-util.el	Sun Jul 30 12:45:36 2006 +0000
+++ b/lisp/url/url-util.el	Sun Jul 30 20:19:36 2006 +0000
@@ -352,17 +352,18 @@
 This is taken from RFC 2396.")
 
 ;;;###autoload
-(defun url-hexify-string (str)
-  "Escape characters in a string."
-  (mapconcat
-   (lambda (char)
-     ;; Fixme: use a char table instead.
-     (if (not (memq char url-unreserved-chars))
-	 (if (> char 255)
-	       (error "Hexifying multibyte character %s" str)
-	   (format "%%%02X" char))
-       (char-to-string char)))
-   str ""))
+(defun url-hexify-string (string)
+  "Return a new string that is STRING URI-encoded.
+First, STRING is converted to utf-8, if necessary.  Then, for each
+character in the utf-8 string, those found in `url-unreserved-chars'
+are left as-is, all others are represented as a three-character
+string: \"%\" followed by two lowercase hex digits."
+  (mapconcat (lambda (char)
+               (if (memq char url-unreserved-chars)
+                   (char-to-string char)
+                 (format "%%%02x" char)))
+             (encode-coding-string string 'utf-8 t)
+             ""))
 
 ;;;###autoload
 (defun url-file-extension (fname &optional x)