[PRL] Looking for 2 bits of emacs code

David Herman dherman at ccs.neu.edu
Thu Apr 24 00:20:49 EDT 2003


Don't know if there's a built-in escape function for the browse-url 
package but here's an approximation:

;; ---
;; http://www.zvon.org/tmRFC/RFC2396/Output/chapter2.html

(defconst lower      (append "abcdefghijklmnopqrstuvwxyz" nil))
(defconst upper      (append "ABCDEFGHIJKLMNOPQRSTUVWXYZ" nil))
(defconst alpha      (append lower upper nil))
(defconst num        (append "0123456789" nil))
(defconst alphanum   (append alpha num nil))
(defconst mark       (append "-_.!~*'()" nil))
(defconst unreserved (append alphanum mark nil))

;; google-url : string -> string
(defun google-url (str)
   (concat "http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q="
           (escape str)
           "&btnG=Google+Searchstr"))

;; escape : string -> string
(defun escape (str)
   (escape-helper (append str nil) ""))

;; escape-helper : (listof char) string -> string
(defun escape-helper (aloc result)
   (if (null aloc)
       result
       (escape-helper (cdr aloc) (concat result (escape-char (car 
aloc))))))

;; escapep : char -> boolean
(defun escapep (c)
   (not (memq c unreserved)))

;; escape-char : char -> char
(defun escape-char (c)
   (cond
     ((eq c ?\ ) "+")
     ((escapep c) (format "%%%x" c))
     (t (string c))))
;; ---

Dave



More information about the PRL mailing list