Apple's new file system APFS brings along new rules for testing file name equality, and they're different from HFS. I am seeking the correct way to compare two names for equality, for APFS in particular, but for completeness it can't hurt to add one for HFS+ checks are well.
Why? Because I need to be able to tell if a file name I find in a directory matches a certain pattern, e.g. contains a certain sub string. For that, I need to match the exact rules the file system and Finder would use for comparing names.
For case-sensitive variants of these file systems it's pretty easy, as a byte-wise compare is sufficient, I believe (provided both strings are using the same encoding).
For case-insensitive HFS+, I thought there was even a special comparison option, but I cannot find such in the NSStringCompareOptions. I believe that was needed because HFS+ uses an older version of the Unicode standard. I quote from the TN1150 (which is, sadly, no longer available at Apple's website, it appears):
Unicode Subtleties
HFS Plus makes heavy use of Unicode strings to store file and folder names. However, Unicode is still evolving, and its use within a file system presents a number of challenges. This section describes some of the challenges, along with the solutions used by HFS Plus.
IMPORTANT: An implementation must not use the Unicode utilities implemented by its native platform (for decomposition and comparison), unless those algorithms are equivalent to the HFS Plus algorithms defined here, and are guaranteed to be so forever. This is rarely the case. Platform algorithms tend to evolve with the Unicode standard. The HFS Plus algorithms cannot evolve because such evolution would invalidate existing HFS Plus volumes.
Ah, and there's the part that I had in mind about getting the HFS+ version of the used encoding:
Note: The Mac OS Text Encoding Converter provides several constants that let you convert to and from the canonical, decomposed form stored on HFS Plus volumes. When using CreateTextEncoding to create a text encoding, you should set the TextEncodingBase to kTextEncodingUnicodeV2_0, set the TextEncodingVariant to kUnicodeCanonicalDecompVariant, and set the TextEncodingFormat to kUnicode16BitFormat. Using these values ensures that the Unicode will be in the same form as on an HFS Plus volume, even as the Unicode standard evolves.
So, what's the modern way to compare HFS+ and APFS names properly?