我需要確定給定的NSString是否處於NFD形式。我怎麼做?如何判斷NSString是否在NFD中被標準化?
語境:
文件路徑我從Mac OS獲得(在一個NSString的形式)爲規範分解形式(NFD)。當文件系統是HFSPlus時尤其如此。 http://developer.apple.com/mac/library/technotes/tn/tn1150.html#CanonicalDecomposition
我需要一個預先分解的字符串。現在,只有當我知道文件名以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中)的理解是否正確?