Just a warning: Once you start implementing your own sort-function,
things become non-trivial when you have to sort non-ascii chars.
On Tue, 3 Jun 2014 00:19:01 -0700 (PDT) 'Catalin' via wx-dev wrote:
Cvwd> wxSortedArrayString uses std::sort which by default is a case
Cvwd> sensitive comparison, and AFAICS it cannot be changed.
You can use a custom comparator with std::sort() doing case-insensitive
comparison.
I think the least intrusive solution would be to allow specifying the comparator function in wxSortedArrayString ctor.
Cvwd> p.s. Would it make sense to change wxSortedArrayString::Insert(const
Cvwd> wxString& str, size_t nIndex, size_t copies) to call Add(str, copies)
Cvwd> and ignore nIndex?
According to the comment before WX_DEFINE_SORTED_TYPEARRAY definition in
wx/dynarray.h, Insert() shouldn't be defined at all for this class... If it
is, there must be a bug somewhere but I'm not brave enough to go looking
for it right now.
I wonder if we can rewrite these macros using templates one day...
E.g. here's a comparion between standard wxArrayString and wxArrayString using Windows' string compare function (German locale):
If we can just ensure that "a" compares the same with "AA" under all
platforms, this would be good enough for me.
...which leads to the question: should wxArrayString(int autoSort) be removed and m_autoSort made protected so that it can be set by wxSortedStringArray?
On Thu, 12 Jun 2014 04:59:04 -0700 (PDT) Catalin wrote:
Cvwd> A few things about wxArrayString when having !wxUSE_STD_CONTAINERS:
Cvwd> - a custom sorting function is only used in wxArrayString::Sort();
There are 2 possibilities:
1. Change this and allow specifying a custom sort function, e.g. in
wxSortedArrayString ctor.
2. Don't use wxSortedArrayString when custom sorting is needed.
Cvwd> - wxArrayString has the following undocumented
Cvwd> constructor wxArrayString(int autoSort); this looks like a bad idea,
Cvwd> because in case m_autoSort == true, wxArrayString::Add() will always
Cvwd> use wxString::Cmp() as the comparison function, so the following
Cvwd> scenario looks erroneous:
Cvwd> create a wxArrayString with autoSort = true;
Cvwd> add some elements - they will be added according to wxString::Cmp();
Cvwd> call Sort(some custom comparison function);
This won't work, Sort() has an assert checking that the array is not
auto-sorted.
Right, I missed that. It's ok then.Regards,C
> > On Fri, 13 Jun 2014 17:49:26 -0700 (PDT) 'Catalin' via wx-dev wrote:
>
> Cvwd> >1. Change this and allow specifying a custom sort function, e.g. in
> Cvwd> > wxSortedArrayString ctor.
One more problem that I see is that in wxUSE_STD_CONTAINERS=1 build, the function type used for sorting is
CMPFUNCwxString taking (wxString*, wxString*)
while wxArrayString::Sort() is documented to use
CompareFunction taking (const wxString &first, const wxString &second).
The latter is easy to pass to a new wxSortedArrayString ctor in wxUSE_STD_CONTAINERS=0, but not to a wxSortedArrayStringBase ctor in wxUSE_STD_CONTAINERS=1.
Should the implementation of wxSortedArrayStringBase change to use a CompareFunction(const wxString &first, const wxString &second) ?
Regards,
C