all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "spamfilteraccount@gmail.com" <spamfilteraccount@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Comparing non-English strings for sorting
Date: Tue, 10 Feb 2009 02:47:41 -0800 (PST)	[thread overview]
Message-ID: <e9ff7e14-d8b2-4b75-9a34-4a00ad2c6019@a12g2000yqm.googlegroups.com> (raw)
In-Reply-To: 290dbf13-a9d6-4c3a-a895-6bd895ab6c52@p37g2000yqd.googlegroups.com

On Feb 10, 7:31 am, "spamfilteracco...@gmail.com"
<spamfilteracco...@gmail.com> wrote:
> Hi,
>
> I see Emacs doesn't have builtin support for sorting non-Engish (UTF,
> Unicode) strings in proper order.
>
> Has anyone written a comparison function which can handle sorting such
> strings if the character order is provided?

I wrote my own func. Wasn't that hard. Let me know if you spot some
error in it or know a better way:


(require 'cl)

(let ((l '("str1" "str2" ...))
      (order "aábcdeéfghijklmnoóöőpqrstuúüűxyvz"))
  (sort l 'my-case-insensitive-nonenglish-string-comparator))


(defun my-case-insensitive-nonenglish-string-comparator (str1 str2)
  (let ((diff (some (lambda (char1 char2)
                      (and (not (equal char1 char2))
                           (cons char1 char2)))
                    (vconcat (downcase str1))
                    (vconcat (downcase str2)))))
    (if diff
        (let* ((char1 (car diff))
               (char2 (cdr diff))
               (pos1 (position char1 order))
               (pos2 (position char2 order)))
          (if (and pos1 pos2)
              (< pos1 pos2)
            (< char1 char2))))))


  reply	other threads:[~2009-02-10 10:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-10  6:31 Comparing non-English strings for sorting spamfilteraccount
2009-02-10 10:47 ` spamfilteraccount [this message]
2009-02-12 23:57   ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e9ff7e14-d8b2-4b75-9a34-4a00ad2c6019@a12g2000yqm.googlegroups.com \
    --to=spamfilteraccount@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.