From d4e06b76962198eb64e6c2826d4695248102037c Mon Sep 17 00:00:00 2001 From: Vincent Reher Date: Sat, 5 Mar 2022 15:14:32 -0800 Subject: Replace listview's binary "Case Insensitive Sort" option with 3 mutually exclusive options: 1. Unicode based (AB...ab) 2. Unicode based, case insensitive (aAbB) 2. Locale based This resolves issue #252. Signed-off-by: Vincent Reher --- libkonq/konq_string_compare.h | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 libkonq/konq_string_compare.h (limited to 'libkonq/konq_string_compare.h') diff --git a/libkonq/konq_string_compare.h b/libkonq/konq_string_compare.h new file mode 100644 index 000000000..8d17d409f --- /dev/null +++ b/libkonq/konq_string_compare.h @@ -0,0 +1,51 @@ +#ifndef KONQ_STRING_COMPARE_H +#define KONQ_STRING_COMPARE_H + +#include "konq_sort_constants.h" + +static inline int stringCompare( + const TextSortOrder sortorder, + const TQString& a, + const TQString& b +) +{ + // Our caller probably determined sortorder from KonqPropsView::getSortOrder() + // but we have a reasonable fallback position for bogus values. + + switch(sortorder) { + + case UNICODE_UNMODIFIED: + /* + * Strictly character code(point) numeric comparison as defined + * by the Unicode Standard that is backward compatible with the + * the ASCII standard. + . */ + return a.compare( b ); + break; + + case UNICODE_CASEINSENSITIVE: + /* + * This is the traditional "case-insensitive" variation on character + * code order that ensures that ASCII lowercase and uppercase alphabetic + * characters are are grouped together instead of being separated by + * non-alphabetic ASCII characters [ \ ] ^ _ ` + */ + return a.lower().compare( b.lower() ); + break; + + case LOCALE_UNMODIFIED: + /* + * This is the pure locale-aware comparison as defined by ICU. + * Note: if LC_COLLATE == 'C' or 'Posix', this will produce same + * result as UNICODE_UNMODIFIED. + */ + return a.localeAwareCompare( b ); + break; + + default: // Treat as UNICODE_UNMODIFIED + return a.compare( b ); + break; + } +} + +#endif // KONQ_STRING_COMPARE_H -- cgit v1.2.3