在韩语字素簇中搜索或比较

发布于 2024-08-18 13:56:50 字数 833 浏览 5 评论 0原文

在我当前的 UISearchBarController 实现中,我在 filterContentForSearchText:scope: 委托方法中使用 [NSString Compare:] 来返回基于相关对象的当您开始输入时,将其 name 属性添加到结果 UITableView 上。

到目前为止,这在英语和韩语中效果很好,但我希望能够在 NSString 定义的字符簇中进行搜索。这仅适用于少数语言,韩语就是其中之一。

在英语中,compare: 在您输入每个字母后都会返回新结果,但在韩语中,一旦您完成了可识别的字素簇,就会生成结果。我希望能够通过构成音节的各个元素来搜索我的韩语对象名称属性。

谁能阐明如何解决这个问题?我确信这与手动搜索 UTF16 字符或利用较低级别的类有关。

干杯!

下面是一个不起作用的具体示例:

`NSString *string1 = @"이"; 
`NSString *string2 = @"ㅣ";
NSRange resultRange = [[string1 decomposedStringWithCanonicalMapping] rangeOfString:    [string2 decomposedStringWithCanonicalMapping] options:(NSLiteralSearch)];

结果始终是 NSNotFound,无论是否有 decomposedStringWithCanonicalMapping

有什么想法吗?

In my current implementation of a UISearchBarController I'm using [NSString compare:] inside the filterContentForSearchText:scope: delegate method to return relevant objects based on their name property to the results UITableView as you start typing.

So far this works great in English and Korean, but what I'd like to be able to do is search within NSString's defined character clusters. This is only applicable for a handfull of languages, of which Korean is one.

In English, compare: returns new results after every letter you enter, but in Korean the results are generated once you complete a recognized grapheme cluster. I would like to be able to search through my Korean objects name property via the individual elements that make up a syllable.

Can anyone shed any light on how to approach this? I'm sure it has something to do with searching through UTF16 characters manually, or by utilising a lower level class.

Cheers!

Here is a specific example that's just not working:

`NSString *string1 = @"이"; 
`NSString *string2 = @"ㅣ";
NSRange resultRange = [[string1 decomposedStringWithCanonicalMapping] rangeOfString:    [string2 decomposedStringWithCanonicalMapping] options:(NSLiteralSearch)];

The result is always NSNotFound, with or without decomposedStringWithCanonicalMapping.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

剩一世无双 2024-08-25 13:56:50

我不是专家,但我认为您不太可能找到适合您想要的解决方案。韩语字符的 Unicode 值与其组成的字素之间似乎没有任何关系。

例如,“æ”是 \uc774,“ㅣ”是 \u3163。从 NSString 的角度来看,它们只是两个不同的字符,彼此之间没有特定的关系。

我怀疑您必须找到或创建字符及其​​字素之间的显式映射,然后编写自己的搜索函数来查阅该映射。

这个很长的页面如果涉及到这一点,Unicode Korean 可以帮助您。它有一个包含所有字符的表,该表表明字符的编号方式及其组成部分之间的某种结构化关系。

I'm no expert, but I think you're very unlikely to find a clean solution for what you want. There doesn't seem to be any relationship between a Korean character's Unicode value and the graphemes that it's made up of.

e.g. "이" is \uc774 and "ㅣ" is \u3163. From the perspective of the NSString, they're just two different characters with no specific relationship to each other.

I suspect that you will have to find or create an explicit mapping between characters and their graphemes, and then write your own search function that consults this mapping.

This very long page on Unicode Korean can help you, if it comes to that. It has a table of all the characters which suggests some structured relation between the way characters are numbered and their components.

温暖的光 2024-08-25 13:56:50

如果将 compare:options 与 NSLiteralString 一起使用,它应该逐个字符进行比较,即 Unicode 代码点,而不考虑字形。 compare: 的默认行为是不使用任何选项。您可以使用 - decomposedStringWithCanonicalMapping 来获取输入字符串的 Unicode 字节,但我不确定它如何与 compare: 交互。

If you use compare:options with NSLiteralString, it should compare character by character, that is, the Unicode code points, regardless of the grapheme. The default behavior of compare: is to use no options. You could use - decomposedStringWithCanonicalMapping to get the Unicode bytes of the input string, but I'm not sure how that would interact with compare:.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文