ios - How to correctly transliterate Cyrillic, without diacritics, using CFStringTransform? -


i trying use cfstringtransform transliterate names entered in russian safe ascii credit card processing. however, when stripping diacritics č becomes c, not transliteration. there anyway can use cfstringtransform, without diacritics? in other words, ч, should return ch, it's supposed in every standard http://en.wikipedia.org/wiki/romanization_of_russian

nsmutablestring *name = [@"романчук" mutablecopy]; cfmutablestringref nameref = (__bridge cfmutablestringref)name; cfstringtransform(nameref, null, kcfstringtransformtolatin, false); //name romančuk cfstringtransform(nameref, null, kcfstringtransformstripcombiningmarks, false); //name romancuk 

create category nsstring , add these methods:

- (nsstring *)tolatinwithdictionary {     nsmutablestring *newstring = [nsmutablestring string];     nsrange range;     nsstring *symbol;     nsstring *newsymbol;      (nsuinteger = 0; < [self length]; ++)     {          //  take regular symbol         range = nsmakerange(i, 1);         symbol = [self substringwithrange:range];         newsymbol = [self transliteratechar:symbol];         if (newsymbol != nil)         {             [newstring appendstring:newsymbol];         }         else         {             [newstring appendstring:symbol];         }     }     return [nsstring stringwithstring:newstring]; }  - (nsstring *)transliteratechar:(nsstring *)symbol {     //  simlicity there     nsarray *cyrillicchars = @[@"а", @"б", @"в", @"г", @"д", @"е", @"ё", @"ж", @"з", @"и", @"й", @"к", @"л", @"м", @"н", @"о", @"п", @"р", @"с", @"т", @"у", @"ф", @"х", @"ц", @"ч", @"ш", @"щ", @"ъ", @"ы", @"ь", @"э", @"ю", @"я"];     nsarray *latinchars = @[@"a", @"b", @"v", @"g", @"d", @"e", @"yo", @"zh", @"z", @"i", @"y", @"k", @"l", @"m", @"n", @"o", @"p", @"r", @"s", @"t", @"u", @"f", @"h", @"ts", @"ch", @"sh", @"shch", @"'", @"y", @"'", @"e", @"yu", @"ya"];     nsdictionary *convertdict = [nsdictionary dictionarywithobjects:latinchars                                                             forkeys:cyrillicchars];     return [convertdict valueforkey:[symbol lowercasestring]]; }  

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -