Cfstring? Transform

Source: Internet
Author: User

Mattt Thompson Writing, Ricky Tan translation, posted on August 6, 2012
About a language is not easy to use, you only need to measure the following two kinds of indicators:

The unity of the API
Implementation quality of the String class
NSString is the leader in the base Class library. NSString is particularly impressive in the days when other languages are still struggling to Nyaya processing Unicode. Not only does anything get done right, NSString can also parse the string into grammatical tags, detect the primary language in the content, and convert it in any character encoding you can think of. It's ridiculously easy to use.

It is very powerful, but it is irresponsible not to mention its seamless conversion (toll-free bridged) cousin Cfmutablestring, or the more special cfstringtransform.

As its CF prefix describes, Cfstringtransform is part of the Core Foundation. This function passes in the following parameters and returns a Boolean to indicate whether the conversion succeeded:

Stringstring. Reverse: If necessary, returns a reversed transformation. The transform parameter in Cfstringtransform involves a lot of content. Here's an overview of what it can do:

Remove accents and diacritical marks

Én?lišh långuãge l?cks iñterêß?ing Diaçrïti??. A string of such a class, which is very useful, is to make the extended Latin character set the ASCII-friendly representation. Use the Kcfstringtransformstripcombiningmarks transform to remove the curved and twisted symbols in any string.

To name Unicode characters

Kcfstringtransformtounicodename allows you to find out the Unicode standard names for special characters, including Emoji. For example: "?????" is converted to "{SHEEP} {DASH SYMBOL} {sparkles}" and "??" becomes "{PIG face}".

Transliteration between different spellings

In addition to the great exception of English, which is inconsistent with its delightful spelling, the writing system generally encodes the language tones into a consistent symbolic representation. European languages generally use the Latin alphabet (plus some diacritical marks), Russia uses the Cyrillic alphabet, Japan uses hiragana and katakana, and Thai, Korean and Arab countries also have their own letters.

Although each language has a special list of tones, some other languages may be missing, and the intersection of all major writing systems is enough to allow you to efficiently transcribe between different letters (don't confuse the translator).

Cfstringtransform can be transcribed between Latin and Arabic, Cyrillic, Greek, Korean (Korean), Hebrew, Japanese (hiragana and katakana), Mandarin, and Thai.

Transformation Input Output
Kcfstringtransformlatinarabic mr?b? ?????
Kcfstringtransformlatincyrillic privetпривет
Kcfstringtransformlatingreek geiásouγει? Σου
Kcfstringtransformlatinhangul annyeonghaseyo?????
Kcfstringtransformlatinhebrew? LWM????
Kcfstringtransformlatinhiragana Hiraganaひらがな
Kcfstringtransformlatinkatakana Katakanaカタカナ
Kcfstringtransformlatinthai S?w?s?dī??????
Kcfstringtransformhiraganakatakanaにほんごニホンゴ
Kcfstringtransformmandarinlatin Chinese zhōng wén
And that's just a constant definition in the core class library! Directly into an ICU transform expression, cfstringtransform can also be used in Latin and Arabic, Armenian, phonetic, Cyrillic, Georgian, Greek, Chinese, Korean, Hebrew, hiragana, Indic (Sanskrit, Gujarati, Punjabi, Kannada, Malayalam, Oriya, Tamil, Telugu), Korean, katakana, Syriac, Thaana, Thai transliteration.

Regularization of user-generated content

A more practical application of string transformations is the regularization of unpredictable user input. Even if your app doesn't handle other languages alone, you should be able to intelligently handle whatever the user enters into your app.

For example, you want to create a searchable movie index on your device that contains greetings from people around the world:

First, apply the Kcfstringtransformtolatin transform to convert all non-English text to the Latin alphabet representation.
Hello! こんにちは!??????! ?????! Hello! →hello! Kon ' nichiha! s?w?s?dī! mr?b?! Nín hǎo!

Then, apply the Kcfstringtransformstripcombiningmarks transform to remove diacritical marks and accents.
Hello! Kon ' nichiha! s?w?s?dī! mr?b?! Nín hǎo! →hello! Kon ' nichiha! swasdi! mrhba! Nin hao!

Finally, the cfstringlowercase is converted to lowercase, and the Cfstringtokenizer Word is used to index the composition.
(Hello, Kon ' Nichiha, SWASDI, Mrhba, Nin, Hao)

By using the same transformations for the text that the user enters, you can implement a generic search, no matter what language the search text or content is!

Cfstringtransform will be a very powerful tool for dealing with your language at your request. And it is, and is only one of the many powerful features waiting for you to boldly invest in the warmth of objective-c.

Cfstring? Transform

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.