List special functions / global functions alphabetically
Is there an existing issue for this feature request?
- [X] I have searched the existing issues
Is your feature request related to a problem?
When configuring a special function, when you are looknig for the function from the drop-down list, the list is in some random order. It would be much more easier to find the correct function if the list was in alphabetical order.
Describe the solution you'd like
I would like the function list to display in alphabetical order.
Describe alternatives you've considered
No response
Additional context
No response
+1
Agreed. And ideally for both colorlcd and B&W. The current list is most likely in the order the functions were added.
Will std::sort handle the UTF-8 translation strings correctly for all languages?
ChatGPT suggest yes (std::sort can be used to sort a mix of ASCII and UTF-8), but extra work is needed to manage it properly... i.e. If you don't use a custom locale comparator, it will sort ASCII then UTF-8, as well as uppercase before lowercase.
https://godbolt.org/z/cWhE6bnhd
Code
#include <iostream>
#include <vector>
#include <algorithm>
#include <locale>
// Custom comparator using std::locale
struct LocaleComparator {
std::locale locale;
LocaleComparator(const std::locale& loc) : locale(loc) {}
bool operator()(const std::string& lhs, const std::string& rhs) const {
return std::use_facet<std::collate<char>>(locale).compare(
lhs.data(), lhs.data() + lhs.size(),
rhs.data(), rhs.data() + rhs.size()) < 0;
}
};
int main() {
// Define the locale, e.g., "en_US.UTF-8" for US English with UTF-8 encoding
std::locale locale("en_US.UTF-8");
// Example list with mixed ASCII and UTF-8 strings
std::vector<std::string> list = {"apple", "Banana", "élan", "Éclair", "apple"};
// Sort the list using the custom comparator
std::sort(list.begin(), list.end(), LocaleComparator(locale));
// Print the sorted list
for (const auto& str : list) {
std::cout << str << std::endl;
}
return 0;
}