aboutsummaryrefslogtreecommitdiff
path: root/emms-url.el
diff options
context:
space:
mode:
authorWilliam Xu <william.xwl@gmail.com>2008-02-12 06:48:00 +0000
committerWilliam Xu <william.xwl@gmail.com>2008-02-12 06:48:00 +0000
commiteb4229b372252d0e709760edcfc1ffe759367b70 (patch)
treeab1bedbc85a2e305b7f66f6b1a8f03af0c6fd75e /emms-url.el
parent5f0591f7fe91bda35c44faa4134870a2296a9d5e (diff)
- emms-url.el: (emms-url-quote, emms-url-quote-plus), New functions
renamed from emms-lyrics-url-quote, emms-lyrics-url-quote-plus defined in emms-lyrics.el. - emms-url.el: (emms-escape-url, emms-url-specials), deleted, since they can only escape ASCII characters, emms-url-quote can handle all characters. - Update affected files accordingly. darcs-hash:20080212064822-cfa61-759d28b271024ab1a17bd23a2444c076d04e55e7.gz
Diffstat (limited to 'emms-url.el')
-rw-r--r--emms-url.el45
1 files changed, 25 insertions, 20 deletions
diff --git a/emms-url.el b/emms-url.el
index 7fe399f..9fca29d 100644
--- a/emms-url.el
+++ b/emms-url.el
@@ -26,28 +26,33 @@
;;; Code:
(require 'url)
+(require 'emms-compat)
-(defvar emms-url-specials
- '((?\ . "%20")
- (?\n . "%0D%0A")
- (?& . "%26")
- (?? . "%3F"))
- "*An alist of characters which must be represented specially in URLs.
-The transformation is the key of the pair.")
+(defun emms-url-quote (s &optional safe)
+ "Replace special characters in S using the `%xx' escape.
+Characters in [a-zA-Z_.-/] and SAFE(default is \"\") will never be
+quoted.
+e.g.,
+ (url-quote \"abc def\") => \"abc%20def\"."
+ (or safe (setq safe ""))
+ (mapconcat (lambda (c)
+ (if (if (string-match "]" safe)
+ ;; ] should be place at the beginning inside []
+ (string-match
+ (format "[]a-zA-Z_.-/%s]"
+ (emms-replace-regexp-in-string "]" "" safe))
+ (char-to-string c))
+ (string-match (format "[a-zA-Z_.-/%s]" safe)
+ (char-to-string c)))
+ (char-to-string c)
+ (format "%%%02x" c)))
+ (string-to-list (encode-coding-string s 'utf-8))
+ ""))
-(defun emms-escape-url (url)
- "Escape specials in URL.
-
-The specials to escape are specified by the `emms-url-specials'
-variable."
- (apply (function concat)
- (mapcar
- (lambda (ch)
- (let ((repl (assoc ch emms-url-specials)))
- (if (null repl)
- (char-to-string ch)
- (cdr repl))))
- (append url nil))))
+(defun emms-url-quote-plus (s &optional safe)
+ "Run (emms-url-quote s \" \"), then replace ` ' with `+'."
+ (emms-replace-regexp-in-string
+ " " "+" (emms-url-quote s (concat safe " "))))
(defun emms-http-content-coding ()
(save-match-data