Implement wxCmpNatural() using the native function under macOS

Use [NSStting localizedStandardCompare:] which is supposed to use the
same order as Finder does.
This commit is contained in:
Vadim Zeitlin
2021-08-25 00:48:01 +02:00
parent 9c0b543c04
commit 96ab1f0824
3 changed files with 15 additions and 2 deletions

View File

@@ -897,11 +897,11 @@ int wxCMPFUNC_CONV wxCmpNaturalGeneric(const wxString& s1, const wxString& s2)
// ----------------------------------------------------------------------------
// If native natural sort function isn't available, use the generic version.
#if !defined(__WINDOWS__)
#if !(defined(__WINDOWS__) || defined(__DARWIN__) || defined(__WXOSX_IPHONE__))
int wxCMPFUNC_CONV wxCmpNatural(const wxString& s1, const wxString& s2)
{
return wxCmpNaturalGeneric(s1, s2);
}
#endif // #if !defined( __WINDOWS__ )
#endif // not a platform with native implementation

View File

@@ -266,3 +266,10 @@ bool wxCocoaLaunch(const char* const* argv, pid_t &pid)
}
#endif
int wxCMPFUNC_CONV wxCmpNatural(const wxString& s1, const wxString& s2)
{
// The values of NSOrdered{Ascending,Same,Descending} are the same as
// expected return values of wxCmpNatural(), so we don't need to convert.
return [wxCFStringRef(s1).AsNSString() localizedStandardCompare: wxCFStringRef(s2).AsNSString()];
}

View File

@@ -844,3 +844,9 @@ TEST_CASE("wxCmpNaturalGeneric", "[wxString][compare]")
CHECK(wxCmpNaturalGeneric("a5th 5", "a 10th 10") > 0);
}
TEST_CASE("wxCmpNatural", "[wxString][compare]")
{
// We can't expect much from the native natural comparison function as it's
// locale-dependent, so just run a simple sanity test
CHECK(wxCmpNatural("same", "same") == 0);
}