From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#18051: 24.3.92; ls-lisp: Sorting; make ls-lisp-string-lessp a normal function? Date: Thu, 21 Aug 2014 11:05:43 +0200 Message-ID: <87y4uixleg.fsf@gmx.de> References: <87ha2f5gp8.fsf@web.de> <87iomvhvdg.fsf@gmx.de> <834myf6mfl.fsf@gnu.org> <87a987ht5r.fsf@gmx.de> <83y4vq6cz3.fsf@gnu.org> <87tx6c7f5v.fsf@web.de> <8338dw5zrf.fsf@gnu.org> <87lhro7dp4.fsf@web.de> <83zjg44jzd.fsf@gnu.org> <87wqb8mqqv.fsf@web.de> <83y4vo4fbr.fsf@gnu.org> <87silwmo8h.fsf@web.de> <83wqb84e7l.fsf@gnu.org> <87iomsgsqg.fsf@gmx.de> <83tx6c44x7.fsf@gnu.org> <87egxggigj.fsf@gmx.de> <877g28w19r.fsf@gmx.de> <83sikvcbqr.fsf@gnu.org> <83r40fc876.fsf@gnu.org> <87wqa7uf7w.fsf@gmx.de> <83oavjc5jj.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1408612053 13957 80.91.229.3 (21 Aug 2014 09:07:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Aug 2014 09:07:33 +0000 (UTC) Cc: michael_heerdegen@web.de, 18051@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 21 11:07:26 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XKOL1-0007JU-Td for geb-bug-gnu-emacs@m.gmane.org; Thu, 21 Aug 2014 11:07:20 +0200 Original-Received: from localhost ([::1]:59574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKOL1-0002rm-E7 for geb-bug-gnu-emacs@m.gmane.org; Thu, 21 Aug 2014 05:07:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKOKq-0002k4-Vx for bug-gnu-emacs@gnu.org; Thu, 21 Aug 2014 05:07:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XKOKk-0003AK-SS for bug-gnu-emacs@gnu.org; Thu, 21 Aug 2014 05:07:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41792) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XKOKk-0003AD-PX for bug-gnu-emacs@gnu.org; Thu, 21 Aug 2014 05:07:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XKOKk-0002x5-Ai for bug-gnu-emacs@gnu.org; Thu, 21 Aug 2014 05:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 21 Aug 2014 09:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18051 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 18051-submit@debbugs.gnu.org id=B18051.140861196511275 (code B ref 18051); Thu, 21 Aug 2014 09:07:02 +0000 Original-Received: (at 18051) by debbugs.gnu.org; 21 Aug 2014 09:06:05 +0000 Original-Received: from localhost ([127.0.0.1]:48735 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XKOJo-0002vl-2p for submit@debbugs.gnu.org; Thu, 21 Aug 2014 05:06:04 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:51648) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XKOJk-0002vC-Az for 18051@debbugs.gnu.org; Thu, 21 Aug 2014 05:06:01 -0400 Original-Received: from detlef.gmx.de ([87.146.32.163]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0LoVja-1WjObS02Ek-00gUMR; Thu, 21 Aug 2014 11:05:52 +0200 In-Reply-To: <83oavjc5jj.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 17 Aug 2014 21:52:32 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux) X-Provags-ID: V03:K0:ujMJp9CmGC2nmcoGIecSTmNhxVVa/0q86WjtLttvfhPH5aIGodY 5TaJihBoPt4zCflpst5ZRhgRDxj/KV8p5FFI6/A1qHArGZq5GfJhjG9Xs0/VKSChtlrMZYs 3GyBED29nWXxFW+dvqiZswI+EAX6c49eHUjKKHOUWCLbRiyIbNTP5Ezue6i/ZXcnnh4b6gA LVVW80GFRgp3dV9p40Q7Q== X-UI-Out-Filterresults: notjunk:1; X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:92555 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> So what, maybe it is sufficient to take over the implementation from >> glib, indeed. There's not too much logic added there, and we would avoid >> the glib dependency. > > That's what I had in mind, yes. Finally, I came out with the appended patch. Comments appreciated. >> do you or somebody else has some test cases for `gstring-lessp' or >> `gstring-equalp', which shall return different results than >> `string-lessp' and `string-equal'? > > I don't have such test cases, but I'd start by looking in the glib > test suite. There aren't so many glib test cases for collation. I need to search further. Best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=collate-patch *** /usr/local/src/emacs/src/fns.c.~117719~ 2014-08-21 10:58:42.195613026 +0200 --- /usr/local/src/emacs/src/fns.c 2014-08-21 10:27:30.986334200 +0200 *************** *** 39,46 **** #if defined (HAVE_X_WINDOWS) #include "xterm.h" #endif ! Lisp_Object Qstring_lessp; static Lisp_Object Qprovide, Qrequire; static Lisp_Object Qyes_or_no_p_history; Lisp_Object Qcursor_in_echo_area; --- 39,52 ---- #if defined (HAVE_X_WINDOWS) #include "xterm.h" #endif + #ifdef HAVE_SETLOCALE + #include + #endif /* HAVE_SETLOCALE */ + #ifdef __STDC_ISO_10646__ + #include + #endif /* __STDC_ISO_10646__ */ ! Lisp_Object Qstring_lessp, Qstring_collate_lessp, Qstring_collate_equalp; static Lisp_Object Qprovide, Qrequire; static Lisp_Object Qyes_or_no_p_history; Lisp_Object Qcursor_in_echo_area; *************** *** 343,348 **** --- 349,467 ---- } return i1 < SCHARS (s2) ? Qt : Qnil; } + + #ifdef __STDC_ISO_10646__ + ptrdiff_t + str_collate (Lisp_Object s1, Lisp_Object s2) + { + register ptrdiff_t res, len, i, i_byte; + wchar_t *p1, *p2; + Lisp_Object lc_collate; + char *old_collate, *saved_collate; + + USE_SAFE_ALLOCA; + + /* Check parameters. */ + if (SYMBOLP (s1)) + s1 = SYMBOL_NAME (s1); + if (SYMBOLP (s2)) + s2 = SYMBOL_NAME (s2); + CHECK_STRING (s1); + CHECK_STRING (s2); + + /* Convert byte stream to code pointers. */ + len = SCHARS (s1); i = i_byte = 0; + p1 = (wchar_t *) SAFE_ALLOCA ((len+1) * (sizeof *p1)); + while (i < len) + FETCH_STRING_CHAR_ADVANCE (*(p1+i-1), s1, i, i_byte); + *(p1+len) = 0; + + len = SCHARS (s2); i = i_byte = 0; + p2 = (wchar_t *) SAFE_ALLOCA ((len+1) * (sizeof *p2)); + while (i < len) + FETCH_STRING_CHAR_ADVANCE (*(p2+i-1), s2, i, i_byte); + *(p2+len) = 0; + + #ifdef HAVE_SETLOCALE + /* Set locale. */ + lc_collate = + Fgetenv_internal (build_string ("LC_COLLATE"), Vprocess_environment); + if (STRINGP (lc_collate)) + { + old_collate = setlocale (LC_COLLATE, NULL); + saved_collate = xstrdup (old_collate); + setlocale (LC_COLLATE, SSDATA (lc_collate)); + } + #endif /* HAVE_SETLOCALE */ + + res = wcscoll (p1, p2); + + #ifdef HAVE_SETLOCALE + /* Restore the original locale. */ + if (STRINGP (lc_collate)) + setlocale (LC_COLLATE, saved_collate); + #endif /* HAVE_SETLOCALE */ + + /* Return result. */ + SAFE_FREE (); + return res; + } + #endif /* __STDC_ISO_10646__ */ + + DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 2, 0, + doc: /* Return t if first arg string is less than second in collation order. + + Case is significant. Symbols are also allowed; their print names are + used instead. + + This function obeys the conventions for collation order in your + locale settings. For example, punctuation and whitespace characters + are considered less significant for sorting. + + \(sort '\("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp) + => \("11" "1 1" "1.1" "12" "1 2" "1.2") + + If your system does not support a locale environment, this function + behaves like `string-lessp'. + + If the environment variable \"LC_COLLATE\" is set in `process-environment', + it overrides the setting of your current locale. */) + (Lisp_Object s1, Lisp_Object s2) + { + #ifdef __STDC_ISO_10646__ + return (str_collate (s1, s2) < 0) ? Qt : Qnil; + #else + return Fstring_lessp (s1, s2); + #endif /* __STDC_ISO_10646__ */ + } + + DEFUN ("string-collate-equalp", Fstring_collate_equalp, Sstring_collate_equalp, 2, 2, 0, + doc: /* Return t if two strings have identical contents. + + Case is significant. Symbols are also allowed; their print names are + used instead. + + This function obeys the conventions for collation order in your locale + settings. For example, characters with different coding points but + the same meaning are considered as equal, like different grave accent + unicode characters. + + \(string-collate-equalp \(string ?\\uFF40) \(string ?\\u1FEF)) + => t + + If your system does not support a locale environment, this function + behaves like `string-equal'. + + If the environment variable \"LC_COLLATE\" is set in `process-environment', + it overrides the setting of your current locale. */) + (Lisp_Object s1, Lisp_Object s2) + { + #ifdef __STDC_ISO_10646__ + return (str_collate (s1, s2) == 0) ? Qt : Qnil; + #else + return Fstring_equal (s1, s2); + #endif /* __STDC_ISO_10646__ */ + } static Lisp_Object concat (ptrdiff_t nargs, Lisp_Object *args, enum Lisp_Type target_type, bool last_special); *************** *** 4919,4924 **** --- 5038,5045 ---- defsubr (&Sdefine_hash_table_test); DEFSYM (Qstring_lessp, "string-lessp"); + DEFSYM (Qstring_collate_lessp, "string-collate-lessp"); + DEFSYM (Qstring_collate_equalp, "string-collate-equalp"); DEFSYM (Qprovide, "provide"); DEFSYM (Qrequire, "require"); DEFSYM (Qyes_or_no_p_history, "yes-or-no-p-history"); *************** *** 4972,4977 **** --- 5093,5100 ---- defsubr (&Sstring_equal); defsubr (&Scompare_strings); defsubr (&Sstring_lessp); + defsubr (&Sstring_collate_lessp); + defsubr (&Sstring_collate_equalp); defsubr (&Sappend); defsubr (&Sconcat); defsubr (&Svconcat); --=-=-=--