不区分大小写的文本列表排序

Case-insensitive text list sorting

有一个列表“спсВыбора”:

("ФайлыКаталоги" "Клиент Проверка Существования Каталога" "Клиент Проверка Существование Файла" "СтандартныеСтруктурыМодуля" "стндОбрОтв" "элКлючаОтветУспехОбрОтв" "элКлючаОтветОшибкаОбрОтв" "элКлючаОтветПроцедура" "элКлючаОтветМодуль" "стндОтчОтв")

要排序,使用命令:

(setq спсВыбора (sort спсВыбора (lambda (a b) (string> a b))))

因此,“спсВыбора”的列表:

("элКлючаОтветУспехОбрОтв" "элКлючаОтветПроцедура" "элКлючаОтветОшибкаОбрОтв" "элКлючаОтветМодуль" "стндОтчОтв" "стндОбрОтв" "ФайлыКаталоги" "СтандартныеСтруктурыМодуля" "Клиент Проверка Существования Каталога" "Клиент Проверка Существование Файла")

排序考虑了大小写字母的单独顺序。告诉我如何通过删除大小写顺序对列表进行排序。示例:

"caB" => "aBc"

如您所见,string< 区分大小写。在你的情况下,我建议获得不区分大小写的排序是 upcase/downcase 该比较器的操作数,这样它实际上是不区分大小写的:

(setq спсВыбора (sort спсВыбора (lambda (a b) (string> (downcase a) (downcase b)))))

请注意,根据您的示例,这是按字母顺序排列的。

使用string-collate-lessp作为谓词:

string-collate-lessp is a built-in function in ‘src/fns.c’.

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

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.

If your system does not support a locale environment, this function
behaves like ‘string-lessp’.