Function: url-hexify-string

url-hexify-string is an autoloaded and byte-compiled function defined in url-util.el.gz.

Signature

(url-hexify-string STRING &optional ALLOWED-CHARS)

Documentation

URI-encode STRING and return the result.

If STRING is multibyte, it is first converted to a utf-8 byte string. Each byte corresponding to an allowed character is left as-is, while all other bytes are converted to a three-character string: "%" followed by two upper-case hex digits.

The allowed characters are specified by ALLOWED-CHARS. If this argument is nil, the list url-unreserved-chars determines the allowed characters. Otherwise, ALLOWED-CHARS should be either a list of allowed chars, or a vector whose Nth element is non-nil if character N is allowed.

Aliases

mh-url-hexify-string (obsolete since 29.1)

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-util.el.gz
;;;###autoload
(defun url-hexify-string (string &optional allowed-chars)
  "URI-encode STRING and return the result.
If STRING is multibyte, it is first converted to a utf-8 byte
string.  Each byte corresponding to an allowed character is left
as-is, while all other bytes are converted to a three-character
string: \"%\" followed by two upper-case hex digits.

The allowed characters are specified by ALLOWED-CHARS.  If this
argument is nil, the list `url-unreserved-chars' determines the
allowed characters.  Otherwise, ALLOWED-CHARS should be either a
list of allowed chars, or a vector whose Nth element is non-nil
if character N is allowed."
  (if allowed-chars
      (unless (vectorp allowed-chars)
        (setq allowed-chars (url--allowed-chars allowed-chars)))
    (setq allowed-chars (url--allowed-chars url-unreserved-chars)))
  (mapconcat (lambda (byte)
	       (if (aref allowed-chars byte)
		   (char-to-string byte)
		 (aref url-encoding-table byte)))
	     (if (multibyte-string-p string)
		 (encode-coding-string string 'utf-8)
	       string)))