Function: string-collate-lessp

string-collate-lessp is a function defined in fns.c.

Signature

(string-collate-lessp S1 S2 &optional LOCALE IGNORE-CASE)

Documentation

Return t if first arg string is less than second in collation order.

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 might be 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")

The optional argument LOCALE, a string, overrides the setting of your current locale identifier for collation. The value is system dependent; a LOCALE "en_US.UTF-8" is applicable on POSIX systems, while it would be, e.g., "enu_USA.1252" on MS-Windows systems.

If IGNORE-CASE is non-nil, characters are converted to lower-case before comparing them.

To emulate Unicode-compliant collation on MS-Windows systems, bind w32-collate-ignore-punctuation to a non-nil value, since the codeset part of the locale cannot be "UTF-8" on MS-Windows.

Some operating systems do not implement correct collation (in specific locale environments or at all). Then, this functions falls back to case-sensitive string-lessp and IGNORE-CASE argument is ignored.

Other relevant functions are documented in the comparison and string groups.

View in manual

Probably introduced at or before Emacs version 25.1.

Shortdoc

;; string
(string-collate-lessp "abc" "abd")
    => t
;; comparison
(string-collate-lessp "abc" "abd")
    => t

Aliases

org-string-collate-lessp (obsolete since 9.6)

Source Code

// Defined in /usr/src/emacs/src/fns.c
{
#if defined __STDC_ISO_10646__ || defined WINDOWSNT
  /* Check parameters.  */
  if (SYMBOLP (s1))
    s1 = SYMBOL_NAME (s1);
  if (SYMBOLP (s2))
    s2 = SYMBOL_NAME (s2);
  CHECK_STRING (s1);
  CHECK_STRING (s2);
  if (!NILP (locale))
    CHECK_STRING (locale);

  return (str_collate (s1, s2, locale, ignore_case) < 0) ? Qt : Qnil;

#else  /* !__STDC_ISO_10646__, !WINDOWSNT */
  return Fstring_lessp (s1, s2);
#endif /* !__STDC_ISO_10646__, !WINDOWSNT */
}