Implement wxUILocale::CompareStrings() for Unix systems
This required changing CompareStrings() to be a method of wxUILocale object, rather than just as a static function, as we must only allocate the locale_t object once, and not during each to this function, as this could make it unusably slow when using it as a comparison function when sorting a large list of strings. This is also more efficient under Mac, where we can similarly allocate NSLocale only once and even marginally more efficient under MSW, where we don't have to construct the locale string during each call. And, under all platforms, it also simplifies code by separating this function implementation from the initialization of wxUILocaleImpl. Also document that case-insensitive comparison is not available under Unix and adjust the tests accordingly.
This commit is contained in:
@@ -47,6 +47,8 @@ public:
|
||||
bool Use() wxOVERRIDE;
|
||||
wxString GetName() const wxOVERRIDE;
|
||||
wxString GetInfo(wxLocaleInfo index, wxLocaleCategory cat) const wxOVERRIDE;
|
||||
int CompareStrings(const wxString& lhs, const wxString& rhs,
|
||||
int flags) const wxOVERRIDE;
|
||||
|
||||
private:
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
@@ -326,6 +328,28 @@ wxUILocaleImplUnix::GetInfo(wxLocaleInfo index, wxLocaleCategory cat) const
|
||||
#endif // HAVE_LANGINFO_H/!HAVE_LANGINFO_H
|
||||
}
|
||||
|
||||
int
|
||||
wxUILocaleImplUnix::CompareStrings(const wxString& lhs, const wxString& rhs,
|
||||
int WXUNUSED(flags)) const
|
||||
{
|
||||
int rc;
|
||||
|
||||
#ifdef HAVE_LOCALE_T
|
||||
if ( m_locale )
|
||||
rc = wcscoll_l(lhs.wc_str(), rhs.wc_str(), m_locale);
|
||||
else
|
||||
#endif // HAVE_LOCALE_T
|
||||
rc = wcscoll(lhs.wc_str(), rhs.wc_str());
|
||||
|
||||
if ( rc < 0 )
|
||||
return -1;
|
||||
|
||||
if ( rc > 0 )
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* static */
|
||||
wxUILocaleImpl* wxUILocaleImpl::CreateStdC()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user