* 2011-03-11 14:07 (-0800), Xah Lee wrote:
> Here's a more polished solution. The “asciify-word-or-selection” is a
> command. It works on current word or text selection.
> (defun asciify-string (inputstr)
> "Make Unicode string into equivalent ASCII ones.
> For example, “passé” becomes “passe”.
> This function works on chars in European languages, and does
> not transcode arbitrary unicode chars (such as Greek).
> Un-transformed unicode char remains in the string."
> (let ()
> (setq inputstr (replace-regexp-in-string "á\\|à\\|â\\|ä\\|ã\\|å"
> "a" inputstr))
> (setq inputstr (replace-regexp-in-string "é\\|è\\|ê\\|ë" "e"
> inputstr))
> (setq inputstr (replace-regexp-in-string "í\\|ì\\|î\\|ï" "i"
> inputstr))
> (setq inputstr (replace-regexp-in-string "ó\\|ò\\|ô\\|ö\\|õ\\|ø"
> "o" inputstr))
> (setq inputstr (replace-regexp-in-string "ú\\|ù\\|û\\|ü" "u"
> inputstr))
> (setq inputstr (replace-regexp-in-string "ñ" "n" inputstr))
> (setq inputstr (replace-regexp-in-string "ç" "c" inputstr))
> (setq inputstr (replace-regexp-in-string "ð" "d" inputstr))
> (setq inputstr (replace-regexp-in-string "þ" "th" inputstr))
> (setq inputstr (replace-regexp-in-string "ß" "ss" inputstr))
> (setq inputstr (replace-regexp-in-string "æ" "ae" inputstr))
> inputstr
> ))
Here's even more polished version:
(defmacro replace-regexp-series (string &rest clauses)
(declare (indent 1))
(let ((value (make-symbol "--value--")))
`(let ((,value ,string))
,@(let (forms)
(dolist (clause clauses (nreverse forms))
(push `(setq ,value (replace-regexp-in-string
,(car clause) ,(cadr clause) ,value))
forms))))))
(defun asciify-string (string)
(replace-regexp-series string
("[áàâäãå]" "a")
("[éèêë]" "e")
("[íìîï]" "i")
("[óòôöõø]" "o")
("[úùûü]" "u")
("ñ" "n")
("ç" "c")
("ð" "d")
("þ" "th")
("ß" "ss")
("æ" "ae")))