Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion emacs lisp: asciify unicode string
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Teemu Likonen  
View profile  
 More options Mar 12 2011, 2:02 am
Newsgroups: comp.lang.lisp, comp.emacs
From: Teemu Likonen <tliko...@iki.fi>
Date: Sat, 12 Mar 2011 09:02:53 +0200
Local: Sat, Mar 12 2011 2:02 am
Subject: Re: emacs lisp: asciify unicode string
* 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")))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.