Use NSLocale rather than CFLocale functions for consistency
We need to use [NSString compare:options:range:locale:], as there is no corresponding CFString function, so use NSLocale functions rather than CFLocale ones too, for consistency. No real changes.
This commit is contained in:
@@ -26,9 +26,6 @@
|
|||||||
#include "wx/osx/core/cfref.h"
|
#include "wx/osx/core/cfref.h"
|
||||||
#include "wx/osx/core/cfstring.h"
|
#include "wx/osx/core/cfstring.h"
|
||||||
|
|
||||||
#include <CoreFoundation/CFLocale.h>
|
|
||||||
#include <CoreFoundation/CFString.h>
|
|
||||||
|
|
||||||
#import <Foundation/NSString.h>
|
#import <Foundation/NSString.h>
|
||||||
#import <Foundation/NSLocale.h>
|
#import <Foundation/NSLocale.h>
|
||||||
|
|
||||||
@@ -73,28 +70,33 @@ namespace
|
|||||||
class wxUILocaleImplCF : public wxUILocaleImpl
|
class wxUILocaleImplCF : public wxUILocaleImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit wxUILocaleImplCF(const wxCFRef<CFLocaleRef>& cfloc)
|
explicit wxUILocaleImplCF(NSLocale* nsloc)
|
||||||
: m_cfloc(cfloc)
|
: m_nsloc([nsloc retain])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~wxUILocaleImplCF() wxOVERRIDE
|
||||||
|
{
|
||||||
|
[m_nsloc release];
|
||||||
|
}
|
||||||
|
|
||||||
static wxUILocaleImplCF* Create(const wxLocaleIdent& locId)
|
static wxUILocaleImplCF* Create(const wxLocaleIdent& locId)
|
||||||
{
|
{
|
||||||
// Surprisingly, CFLocaleCreate() always succeeds, even for completely
|
// Surprisingly, localeWithLocaleIdentifier: always succeeds, even for
|
||||||
// invalid strings, so we need to check if the name is actually in the
|
// completely invalid strings, so we need to check if the name is
|
||||||
// list of the supported locales ourselves.
|
// actually in the list of the supported locales ourselves.
|
||||||
static wxCFRef<CFArrayRef>
|
static wxCFRef<CFArrayRef>
|
||||||
all = CFLocaleCopyAvailableLocaleIdentifiers();
|
all((CFArrayRef)[NSLocale availableLocaleIdentifiers]);
|
||||||
|
|
||||||
wxCFStringRef cfName(locId.GetName());
|
wxCFStringRef cfName(locId.GetName());
|
||||||
if ( !CFArrayContainsValue(all, CFRangeMake(0, CFArrayGetCount(all)), cfName) )
|
if ( ![(NSArray*)all.get() containsObject: cfName.AsNSString()] )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
CFLocaleRef cfloc = CFLocaleCreate(kCFAllocatorDefault, cfName);
|
auto nsloc = [NSLocale localeWithLocaleIdentifier: cfName.AsNSString()];
|
||||||
if ( !cfloc )
|
if ( !nsloc )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return new wxUILocaleImplCF(cfloc);
|
return new wxUILocaleImplCF(nsloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Use() wxOVERRIDE;
|
void Use() wxOVERRIDE;
|
||||||
@@ -104,7 +106,7 @@ public:
|
|||||||
int flags) const wxOVERRIDE;
|
int flags) const wxOVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxCFRef<CFLocaleRef> m_cfloc;
|
NSLocale* const m_nsloc;
|
||||||
|
|
||||||
wxDECLARE_NO_COPY_CLASS(wxUILocaleImplCF);
|
wxDECLARE_NO_COPY_CLASS(wxUILocaleImplCF);
|
||||||
};
|
};
|
||||||
@@ -125,13 +127,13 @@ wxUILocaleImplCF::Use()
|
|||||||
wxString
|
wxString
|
||||||
wxUILocaleImplCF::GetName() const
|
wxUILocaleImplCF::GetName() const
|
||||||
{
|
{
|
||||||
return wxCFStringRef::AsString(CFLocaleGetIdentifier(m_cfloc));
|
return wxCFStringRef::AsString([m_nsloc localeIdentifier]);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString
|
wxString
|
||||||
wxUILocaleImplCF::GetInfo(wxLocaleInfo index, wxLocaleCategory cat) const
|
wxUILocaleImplCF::GetInfo(wxLocaleInfo index, wxLocaleCategory cat) const
|
||||||
{
|
{
|
||||||
return wxGetInfoFromCFLocale(m_cfloc, index, cat);
|
return wxGetInfoFromCFLocale((CFLocaleRef)m_nsloc, index, cat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
@@ -143,7 +145,7 @@ wxUILocaleImpl* wxUILocaleImpl::CreateStdC()
|
|||||||
/* static */
|
/* static */
|
||||||
wxUILocaleImpl* wxUILocaleImpl::CreateUserDefault()
|
wxUILocaleImpl* wxUILocaleImpl::CreateUserDefault()
|
||||||
{
|
{
|
||||||
return new wxUILocaleImplCF(CFLocaleCopyCurrent());
|
return new wxUILocaleImplCF([NSLocale currentLocale]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
@@ -167,7 +169,7 @@ wxUILocaleImplCF::CompareStrings(const wxString& lhs, const wxString& rhs,
|
|||||||
NSComparisonResult ret = [ns_lhs compare:ns_rhs
|
NSComparisonResult ret = [ns_lhs compare:ns_rhs
|
||||||
options:options
|
options:options
|
||||||
range:(NSRange){0, [ns_lhs length]}
|
range:(NSRange){0, [ns_lhs length]}
|
||||||
locale:(id)(CFLocaleRef)m_cfloc];
|
locale:m_nsloc];
|
||||||
|
|
||||||
switch (ret)
|
switch (ret)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user