(defalias 'send-region 'process-send-region)
(defalias 'string= 'string-equal)
(defalias 'string< 'string-lessp)
+(defalias 'string> 'string-greaterp)
(defalias 'move-marker 'set-marker)
(defalias 'rplaca 'setcar)
(defalias 'rplacd 'setcdr)
(if (string-match "\\cR" str)
(concat str (propertize (string ?\x200e) 'invisible t))
str))
+
+(defun string-greaterp (string1 string2)
+ "Return non-nil if STRING1 is greater than STRING2 in lexicographic order.
+Case is significant.
+Symbols are also allowed; their print names are used instead."
+ (string-lessp string2 string1))
+
\f
;;;; Specifying things to do later.
}
DEFUN ("string-lessp", Fstring_lessp, Sstring_lessp, 2, 2, 0,
- doc: /* Return t if first arg string is less than second in lexicographic order.
+ doc: /* Return non-nil if STRING1 is less than STRING2 in lexicographic order.
Case is significant.
Symbols are also allowed; their print names are used instead. */)
- (register Lisp_Object s1, Lisp_Object s2)
+ (register Lisp_Object string1, Lisp_Object string2)
{
register ptrdiff_t end;
register ptrdiff_t i1, i1_byte, i2, i2_byte;
- if (SYMBOLP (s1))
- s1 = SYMBOL_NAME (s1);
- if (SYMBOLP (s2))
- s2 = SYMBOL_NAME (s2);
- CHECK_STRING (s1);
- CHECK_STRING (s2);
+ if (SYMBOLP (string1))
+ string1 = SYMBOL_NAME (string1);
+ if (SYMBOLP (string2))
+ string2 = SYMBOL_NAME (string2);
+ CHECK_STRING (string1);
+ CHECK_STRING (string2);
i1 = i1_byte = i2 = i2_byte = 0;
- end = SCHARS (s1);
- if (end > SCHARS (s2))
- end = SCHARS (s2);
+ end = SCHARS (string1);
+ if (end > SCHARS (string2))
+ end = SCHARS (string2);
while (i1 < end)
{
characters, not just the bytes. */
int c1, c2;
- FETCH_STRING_CHAR_ADVANCE (c1, s1, i1, i1_byte);
- FETCH_STRING_CHAR_ADVANCE (c2, s2, i2, i2_byte);
+ FETCH_STRING_CHAR_ADVANCE (c1, string1, i1, i1_byte);
+ FETCH_STRING_CHAR_ADVANCE (c2, string2, i2, i2_byte);
if (c1 != c2)
return c1 < c2 ? Qt : Qnil;
}
- return i1 < SCHARS (s2) ? Qt : Qnil;
+ return i1 < SCHARS (string2) ? Qt : Qnil;
}
DEFUN ("string-collate-lessp", Fstring_collate_lessp, Sstring_collate_lessp, 2, 4, 0,
;; Copyright (C) 2015 Free Software Foundation, Inc.
-;; Author: Oleh Krehel <ohwoeowho@gmail.com>
+;; Author: Oleh Krehel <ohwoeowho@gmail.com>,
+;; Nicolas Petton <nicolas@petton.fr>
;; Keywords:
;; This file is part of GNU Emacs.
(quote
(0 font-lock-keyword-face))))))))
+(ert-deftest string-comparison-test ()
+ (should (string-lessp "abc" "acb"))
+ (should (string-lessp "aBc" "abc"))
+ (should (string-lessp "abc" "abcd"))
+ (should (string-lessp "abc" "abcd"))
+ (should-not (string-lessp "abc" "abc"))
+ (should-not (string-lessp "" ""))
+
+ (should (string-greaterp "acb" "abc"))
+ (should (string-greaterp "abc" "aBc"))
+ (should (string-greaterp "abcd" "abc"))
+ (should (string-greaterp "abcd" "abc"))
+ (should-not (string-greaterp "abc" "abc"))
+ (should-not (string-greaterp "" ""))
+
+ ;; Symbols are also accepted
+ (should (string-lessp 'abc 'acb))
+ (should (string-lessp "abc" 'acb))
+ (should (string-greaterp 'acb 'abc))
+ (should (string-greaterp "acb" 'abc)))
+
(provide 'subr-tests)
;;; subr-tests.el ends here