我需要实现一种方法,用于比较两个字符串的相等性,考虑到某些土耳其字母被视为拉丁字母(例如:ı = i)。这是程序中的瓶颈,因此需要尽可能高效地实现。
我不能使用NSString compare: withOption:nsdiactricinsensitivesearch,因为它无法正确处理土耳其字母。
以下是我的算法实现:
- (NSComparisonResult) compareTurkishSymbol:(unichar)ch with:(unichar)another
{
//needs to be implemented
//code like: if (ch == 'ı') doesn't work correctly
}
- (NSComparisonResult)compareTurkish:(NSString*)word with:(NSString*)another
{
NSUInteger i;
for (i =0; i < word.length; ++i) {
NSComparisonResult result =[self compareTurkishSymbol:[word characterAtIndex:i] with:[another characterAtIndex:i]];
if (result != NSOrderedSame) {
return result;
}
}
return another.length > word.length ? NSOrderedDescending : NSOrderedSame;
}
问题在于我无法正确比较unichars。它不能正确比较非ASCII符号。如何解决这个问题?
NSDiacriticInsensitiveSearch
,因为它无法处理所有土耳其非拉丁符号。 - Rustam Ganeyev