diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2023-02-06 15:26:53 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2023-02-06 15:26:53 +0100 |
| commit | dc51880e28aed7ef82c78a8876bb9f95573beefe (patch) | |
| tree | da9846e19a13bd6278f6cbf607c62e97325371ef /src/Fl_Browser_.cxx | |
| parent | 587687629ee11ac427d26fed5a729c0fc3ed7b9c (diff) | |
Fix "\todo Add a flag to ignore case" from Fl_Browser_.cxx
Diffstat (limited to 'src/Fl_Browser_.cxx')
| -rw-r--r-- | src/Fl_Browser_.cxx | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Fl_Browser_.cxx b/src/Fl_Browser_.cxx index d2dcbc39e..e6c81d1d1 100644 --- a/src/Fl_Browser_.cxx +++ b/src/Fl_Browser_.cxx @@ -984,15 +984,17 @@ Fl_Browser_::Fl_Browser_(int X, int Y, int W, int H, const char* L) item_swap(void*, void*) and item_text(void*) must be implemented for this call. \param[in] flags FL_SORT_ASCENDING -- sort in ascending order\n FL_SORT_DESCENDING -- sort in descending order\n + FL_SORT_CASEINSENSITIVE -- add this to sort case-insensitively\n Values other than the above will cause undefined behavior\n Other flags may appear in the future. - \todo Add a flag to ignore case */ void Fl_Browser_::sort(int flags) { // // Simple bubble sort - pure lazyness on my side. // int i, j, n = -1, desc = ((flags&FL_SORT_DESCENDING)==FL_SORT_DESCENDING); + typedef int (*sort_f_type)(const char *, const char *); + sort_f_type sort_f = ( (flags&FL_SORT_CASEINSENSITIVE) ? strcasecmp : strcmp ); void *a =item_first(), *b, *c; if (!a) return; while (a) { @@ -1008,12 +1010,12 @@ void Fl_Browser_::sort(int flags) { const char *tb = item_text(b); c = item_next(b); if (desc) { - if (strcmp(ta, tb)<0) { + if (sort_f(ta, tb) < 0) { item_swap(a, b); swapped = 1; } } else { - if (strcmp(ta, tb)>0) { + if (sort_f(ta, tb)>0) { item_swap(a, b); swapped = 1; } |
