iOS CFStringTransform 智能地处理用户的输入内容:应用场景{索引}【修订版】

2021-07-05 20:48:50 浏览数 (1)

  • 1.1 Transform identifiers
    • 1.1.1 不同拼写之间的转换
    • 1.1.2 去掉重音和变音符号
    • 1.1.3 找出特殊字符的 Unicode 标准名
  • 2.1 原理
  • 2.2 demo 源码

前言

iOS处理语言工具CFStringTransform :智能地处理用户的输入内容,经典应用场景【索引】

  • 从CSDN下载通讯录demo源码

https://download.csdn.net/download/u011018979/19088189 1、原理:通过对用户输入内容,利用CFStringTransform变换,可以轻松实现实现一个通用的搜索index 2、 特色:搜索内容可以是多语言的 3、文章:https://kunnan.blog.csdn.net/article/details/109603377

I、 CFStringTransform 初识

很明显CFStringTransform 是 Core Foundation 中的一部分

代码语言:javascript复制

/* Perform string transliteration.  The transformation represented by transform is applied to the given range of string, modifying it in place. Only the specified range will be modified, but the transform may look at portions of the string outside that range for context. NULL range pointer causes the whole string to be transformed. On return, range is modified to reflect the new range corresponding to the original range. reverse indicates that the inverse transform should be used instead, if it exists. If the transform is successful, true is returned; if unsuccessful, false. Reasons for the transform being unsuccessful include an invalid transform identifier, or attempting to reverse an irreversible transform.

You can pass one of the predefined transforms below, or any valid ICU transform ID as defined in the ICU User Guide. Note that we do not support arbitrary set of ICU transform rules.
*/

CF_EXPORT
Boolean CFStringTransform(CFMutableStringRef string, CFRange *range, CFStringRef transform, Boolean reverse);

第一个参数CFMutableStringRef:要转换的字符串 第二个参数CFRange 作用范围:NULL,视为全部转换 第三个参数 Transform identifiers->指定要进行什么样的转换 第四个参数reverse:是否采用可逆变换

接下来重点讲解下Transform identifiers

1.1 Transform identifiers

1.1.1 不同拼写之间的转换

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

中文

zhōng wén

kCFStringTransformToLatin 非英文文本转换为拉丁字母

1.1.2 去掉重音和变音符号


  • kCFStringTransformStripCombiningMarks

1.1.3 找出特殊字符的 Unicode 标准名

  • kCFStringTransformToUnicodeName包括 Emoji

0 人点赞