help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing non-English strings for sorting


From: address@hidden
Subject: Re: Comparing non-English strings for sorting
Date: Tue, 10 Feb 2009 02:47:41 -0800 (PST)
User-agent: G2/1.0

On Feb 10, 7:31 am, "address@hidden"
<address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]