summaryrefslogtreecommitdiffstats
path: root/libkonq/konq_string_compare.h
blob: ee96c70568fcf1d81f00924feb0b05657cade56a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#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;

    /*
    case LOCALE_CASEINSENSITIVE:
      /*
       * Unimplemented case would reproduce effect that the legacy
       * option "Case Insensitive Sort" previously had on listviews.
       * It has subtle but undesirable side effects for the en_US
       * locale and probably other locales. For example: while
       * 'a' will sort just before 'A', 'ā' will sort just AFTER 'Ā'.
      * /
      return a.lower().localeAwareCompare( b.lower() );
      break;
    */

    default: // Treat as UNICODE_UNMODIFIED
      return a.compare( b );
      break;
  }
}

/*

The above function implements a string comparison function whose operation varies
depending on the "sortorder" the caller specifies. Calls are to it is intended to
(eventually) replace code in the following konqueror view-specific comparison
functions that are called many times when sorting:

*  konqueror/listview/konq_listviewitems.cpp: KonqBaseListViewItem::compare()
   Replaces the following code at end of function:

     if ( m_pListViewWidget->caseInsensitiveSort() )
         return text( col ).lower().localeAwareCompare( k->text( col ).lower() );
     else {
         return m_pListViewWidget->m_pSettings->caseSensitiveCompare( text( col ), k->text( col ) );

*  libkonq/tdefileivi.cpp: KFileIVI::compare()
   Replaces the following code at end of function:

     if ( view->caseInsensitiveSort() )
          return key().localeAwareCompare( i->key() );
     else
          return view->m_pSettings->caseSensitiveCompare( key(), i->key() );

   Notice that unlike the listview function referenced above, this function does
   NOT use lower() in calls to localeAwareCompare() for caseInsensitveSort.

*  libkonq/KonqFMSettings::caseSensitiveCompare()
   Obsoletes entire function thereby addressing issue 252.

The above 2 functions will need to remain in place until iconview is retrofitted
with user interface and code to bring it up to par with listview.

Please leave this comment in this header until above changes have been made.

*/

#endif // KONQ_STRING_COMPARE_H