我需要确定给定的 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 中)的理解是否正确?