logoalt Hacker News

Rendello • today at 7:21 PM • 0 replies • view on HN

Lowercasing is not guaranteed to be stable between Unicode versions. If you're looking for stable string matching, use "case folding" instead. Instead of:

    lower(a) == lower(b)             // or,
    lower(needle) in lower(haystack)
Use:

    casefold(a) == casefold(b)             // or,
    casefold(needle) in casefold(haystack)
It's equivalent to lowercasing in almost all cases, but with a stability constraint between across Unicode editions. As per the Unicode stability policy [1]:

> Case folding is not the same as lowercasing, and a case-folded string is not necessarily lowercase. In particular, as of Unicode 8.0, Cherokee has become a bicameral script with the introduction of lowercase Cherokee letters, but Cherokee text case folds to the existing uppercase letters. This case folding behavior for Cherokee text is precisely to guarantee continued case folding stability.

Casing in Unicode can be tricky. The case mapping FAQ [2] is a good place to start. If you need more information, start scanning through the Core Spec and following the case-related links [3].

1. https://www.unicode.org/policies/stability_policy.html#:~:te...

2. https://www.unicode.org/faq/casemap_charprop.html#casemap

3. https://www.unicode.org/versions/Unicode17.0.0/core-spec/cha...