readium / swift-toolkit

A toolkit for ebooks, audiobooks and comics written in Swift
https://readium.org/mobile/
BSD 3-Clause "New" or "Revised" License
222 stars 96 forks source link

Change `localizedCaseInsensitiveCompare` to `localizedStandardCompare` #451

Closed domkm closed 3 weeks ago

domkm commented 3 weeks ago

Both Finder and Files sort by name using localizedStandardCompare. By using localizedCaseInsensitiveCompare, we introduce potentially counterintuitive behavior. For example, a user may import multiple files which appear to be sorted correctly in Finder/Files and then discover that we play them in a different order.

Like localizedCaseInsensitiveCompare, localizedStandardCompare is also case insensitive, but also accounts for numeric non-lexicographic sorting. For example (1...25).map { String($0) } will not change order when sorted with localizedStandardCompare, but with localizedCaseInsensitiveCompare the order will change to ["1", "10", "11", "12", ...].

I also noticed localizedCaseInsensitiveContains being used. Based on my reading of the code, I think normal contains may be appropriate, but, if not, perhaps localizedStandardContains should be used instead. https://github.com/readium/swift-toolkit/blob/8fad4d5acd4603270c9d333545b58a6fb649d98d/Sources/Navigator/EPUB/CSS/ReadiumCSS.swift#L140-L144