-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcollator.mm
More file actions
61 lines (52 loc) · 2.28 KB
/
Copy pathcollator.mm
File metadata and controls
61 lines (52 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright © 2021 CCP ehf.
#include "stdafx.h"
#include "collator.h"
#if __APPLE__
#import "Foundation/Foundation.h"
// -------------------------------------------------------------
// Description:
// The comparison function compares the character data stored in two different strings.
// Returns information about whether a string is less than, greater than or equal to another string.
// Arguments:
// source - the string to be compared with.
// target - the string that is to be compared with the source string.
// Return Value:
// -1 if source is lesser than target, 0 if equal and 1 if source is greater than target.
// -------------------------------------------------------------
int Collator::Compare( const std::wstring& source, const std::wstring& target ) const
{
// Workaround for std::collate bug on macOS
// https://jira.ccpgames.com/browse/EO-14241
NSString *nsSource = [[NSString alloc] initWithBytes:source.data()
length:source.size() * sizeof(wchar_t)
encoding:NSUTF32LittleEndianStringEncoding];
NSString *nsTarget = [[NSString alloc] initWithBytes:target.data()
length:target.size() * sizeof(wchar_t)
encoding:NSUTF32LittleEndianStringEncoding];
NSInteger ret = [nsSource compare:nsTarget
options:NSCaseInsensitiveSearch | NSNumericSearch
range:NSMakeRange(0, nsSource.length)
locale:m_locale];
#if !__has_feature(objc_arc)
[nsSource release];
[nsTarget release];
#endif
return ret;
}
// -------------------------------------------------------------
// Description:
// Sets the locale for this collator.
// Arguments:
// languageCode - string representation of the locale as used in Python
// -------------------------------------------------------------
void Collator::SetLocale( const std::string& languageCode )
{
m_localeID = CodeToLanguageID( languageCode.c_str() );
#if !__has_feature(objc_arc)
[m_locale release];
[m_localeName release];
#endif
m_localeName = [NSString stringWithUTF8String:LanguageIDToLocaleName( m_localeID )];
m_locale = [NSLocale localeWithLocaleIdentifier:m_localeName];
}
#endif