OS X - how to calculate normalized file name

前端 未结 3 1110
孤街浪徒
孤街浪徒 2021-01-13 02:28

I need to create a mapping between file names generated on Windows and OS X. I know that OS X \"converts all file names to decomposed Unicode\" however, \"most volume forma

3条回答
  •  滥情空心
    2021-01-13 02:52

    According to your link, filesystem drivers appear to (mostly) follow one of two behaviours: * Return all names in NFD, and convert names as appropriate. * Don't perform any conversions.

    In both these cases, if you create a file on OSX in NFD, reading it back on OSX should give you the name in NFD.

    OTOH, if your filename goes from Windows → NFS → Mac and you want to do some sort of sync, you're out of luck. This is not an easy thing to do, since the underlying problem is a little philosophical: Should filenames be byte strings or Unicode strings? I believe Unix traditionally does the former, and at least in Linux, UTF-8 NFC names are merely a convention.

    (It gets worse, since IIRC HFS+ is defined to use Unicode 3.something, so a naïve conversion to NFD might be wrong for characters added/changed since then unless the API you use can guarantee a specific Unicode version.)

提交回复
热议问题