いくつかのトルコ語文字をラテン文字 (例: ı = i) と見なして、2 つの文字列が等しいかどうかを比較するメソッドを実装する必要があります。これはプログラムのボトルネックなので、できるだけ効率的に実装する必要があります。
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シンボルを正しく比較しません。それに対処する方法は?