APPROVE COMMIT
NOTE: This patch has been committed
# HG changeset patch
# User Aidan Kehoe <kehoea(a)parhasard.net>
# Date 1530777806 -3600
# Thu Jul 05 09:03:26 2018 +0100
# Node ID e26b605e4e9cddbb7645b9b8137612cf9d6b0f77
# Parent 79bef0ac9919c5b37620c5dc80a75d1a8bf64b00
Make #'compare-menu-text more Mule-clean.
src/ChangeLog addition:
2018-07-05 Aidan Kehoe <kehoea(a)parhasard.net>
* menubar.c (Fcompare_menu_text):
Make this function more Mule-clean, don't give the wrong answer
when there are zero characters within the strings to be compared.
tests/ChangeLog addition:
2018-07-05 Aidan Kehoe <kehoea(a)parhasard.net>
* automated/lisp-tests.el (featurep):
Basic tests of compare-menu-text.
diff -r 79bef0ac9919 -r e26b605e4e9c src/ChangeLog
--- a/src/ChangeLog Thu Jul 05 08:12:49 2018 +0100
+++ b/src/ChangeLog Thu Jul 05 09:03:26 2018 +0100
@@ -1,3 +1,9 @@
+2018-07-05 Aidan Kehoe <kehoea(a)parhasard.net>
+
+ * menubar.c (Fcompare_menu_text):
+ Make this function more Mule-clean, don't give the wrong answer
+ when there are zero characters within the strings to be compared.
+
2018-07-05 Aidan Kehoe <kehoea(a)parhasard.net>
* menubar.c:
diff -r 79bef0ac9919 -r e26b605e4e9c src/menubar.c
--- a/src/menubar.c Thu Jul 05 08:12:49 2018 +0100
+++ b/src/menubar.c Thu Jul 05 09:03:26 2018 +0100
@@ -333,28 +333,57 @@
*/
(string1, string2))
{
- Ibyte *p;
- Ibyte *q;
+ const Ibyte *p, *pend;
+ const Ibyte *q, *qend;
CHECK_STRING (string1);
CHECK_STRING (string2);
p = XSTRING_DATA (string1);
+ pend = p + XSTRING_LENGTH (string1);
q = XSTRING_DATA (string2);
+ qend = q + XSTRING_LENGTH (string2);
for (;;)
{
Ichar val;
- if (*p == '%' && *(p + 1) == '%')
- p++;
- else if (*p == '%' && *(p + 1) == '_')
- p += 2;
- if (*q == '%' && *(q + 1) == '%')
- q++;
- else if (*q == '%' && *(q + 1) == '_')
- q += 2;
- if (!*p || !*q)
- return make_fixnum (*p - *q);
+
+ if ((p + ichar_len ('%')) < pend && itext_ichar_eql (p,
'%'))
+ {
+ if (itext_ichar_eql (p + ichar_len ('%'), '%'))
+ {
+ p += ichar_len ('%');
+ }
+ else if (itext_ichar_eql (p + ichar_len ('%'), '_'))
+ {
+ p += ichar_len ('%');
+ p += ichar_len ('_');
+ }
+ }
+
+ if (p == pend)
+ {
+ return make_fixnum (- itext_ichar (q));
+ }
+
+ if ((q + ichar_len ('%')) < qend && itext_ichar_eql (q,
'%'))
+ {
+ if (itext_ichar_eql (q + ichar_len ('%'), '%'))
+ {
+ q += ichar_len ('%');
+ }
+ else if (itext_ichar_eql (q + ichar_len ('%'), '_'))
+ {
+ q += ichar_len ('%');
+ q += ichar_len ('_');
+ }
+ }
+
+ if (q == qend)
+ {
+ return make_fixnum (itext_ichar (p));
+ }
+
val = DOWNCASE (0, itext_ichar (p)) - DOWNCASE (0, itext_ichar (q));
if (val)
return make_fixnum (val);
diff -r 79bef0ac9919 -r e26b605e4e9c tests/ChangeLog
--- a/tests/ChangeLog Thu Jul 05 08:12:49 2018 +0100
+++ b/tests/ChangeLog Thu Jul 05 09:03:26 2018 +0100
@@ -1,5 +1,8 @@
2018-07-05 Aidan Kehoe <kehoea(a)parhasard.net>
+ * automated/lisp-tests.el (featurep):
+ Basic tests of compare-menu-text.
+
* automated/extent-tests.el:
#'normalize-menu-text is now available even on builds without the
menubar feature, test it even then.
diff -r 79bef0ac9919 -r e26b605e4e9c tests/automated/lisp-tests.el
--- a/tests/automated/lisp-tests.el Thu Jul 05 08:12:49 2018 +0100
+++ b/tests/automated/lisp-tests.el Thu Jul 05 09:03:26 2018 +0100
@@ -4396,4 +4396,20 @@
(Assert (not (true-list-p [])))
(Assert (not (true-list-p -1)))
+;;-----------------------------------------------------
+;; Testing compare-menu-text
+;;-----------------------------------------------------
+
+(when (featurep 'menubar)
+ (Assert (eql 0 (compare-menu-text "a" "a")))
+ (Assert (eql 0 (compare-menu-text "%_a" "a")))
+ (Assert (eql 0 (compare-menu-text "a%" "a%%")))
+ (Assert (eql (- ?b ?a) (compare-menu-text "b" "a")))
+ (Assert (eql (- ?a ?b) (compare-menu-text "a" "b")))
+ ;; This used to give zero, since the function assumed a zero char was the
+ ;; end of the string as in C.
+ (Assert (eql (- ?b) (compare-menu-text "a\000" "a\000bcdef"))))
+
+;; See extent-tests.el for normalize-menu-text, checked in passing.
+
;;; end of lisp-tests.el
--
‘As I sat looking up at the Guinness ad, I could never figure out /
How your man stayed up on the surfboard after forty pints of stout’
(C. Moore)
Show replies by date