【发布时间】:2011-04-09 01:16:33
【问题描述】:
我需要确定给定的 NSString 是否为 NFD 形式。我该怎么做?
上下文:
我从 Mac OS 获得的文件路径(以 NSString 的形式)是规范分解形式 (NFD)。当文件系统是 HFSPlus 时尤其如此。 http://developer.apple.com/mac/library/technotes/tn/tn1150.html#CanonicalDecomposition
我需要一个预先组合的字符串。现在,我只想运行precomposedStringWithCanonicalMapping 函数,前提是我知道文件名以 NFD 形式分解。
我能想到的解决方案:
//works on the idea that NFD(NFD(x)) = NFD(x)
BOOL IsCanonicallyDecompsed(NSString *initialFilePath) {
//decompose the string to NFD form
NSString *nfdFormOfStr = [initialFilePath decomposedStringWithCanonicalMapping];
char *ndfFormUTF8 = [nfdFormOfStr UTF8String];
char *intialPathUTF8 = [initialFilePath UTF8String];
return (strcmp(ndfFormUTF8, intialPathUTF8) == 0);
}
我的解决方案好吗?另外,我对文件系统输出(在 NFD 中)的理解是否正确?
【问题讨论】:
标签: objective-c unicode nsstring normalization unicode-normalization