Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As it isn't yet mentioned: for these cases the Python standard library explicitly has https://docs.python.org/3.8/library/stdtypes.html#str.casefo... (str.casefold), which aggressively lowercase-normalizes strings with an algorithm from the unicode standard. Every case comparison using lower() instead of casefold() can be considered a bug.


> Every case comparison using lower() instead of casefold() can be considered a bug.

If you just casefold two strings and compare them, it's still a bug. You need to normalize them to NFKC first.


Is NFKC necessary, isn't NFKD enough? (As in you have to normalize and decompose both strings, but at that point you can check them for equality, and doing the canonical composition isn't needed, right?)


I think that would work if you're just checking for equality and want to minimize processing. I guess as a web developer I always just assume people are going to be storing strings in a database after normalizing them, so would want to minimize string length.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: