How hard is it to check for whitespace?
Web page · https://serce.me/posts/2026-10-30-how-hard-is-it-to-check-for-whitespace
First seen by Oriel on .
AI summary
The article explains why whitespace checks vary across runtimes and shows how Guava uses a perfect hash function to test Unicode whitespace characters efficiently.
- Unicode's White_Space property contains 25 characters, but Java excludes three non-breaking spaces, Python recognizes 29 characters, and JavaScript's regex \s uses a different set.
- Whitespace definitions can change: Unicode 6.3 removed U+180E from the property, creating compatibility challenges for runtimes and libraries.
- Guava multiplies a character by 1682554634, shifts the result to select one of 32 table slots, and checks the stored character to avoid false matches.
- The article traces Guava's implementation through simpler matching and a mod-79 approach; the latter involved division, while the final method uses perfect hashing.
#unicode #java #perfect hashing #character encoding
Generated by gpt-5.6-sol. Check the original for details.
Metric trends
Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained
Points
Score reported by the source.
- Hacker News: 125, latest observation ; +117 over observed period since
- Lobsters: 47, latest observation ; +46 over observed period since
Comments
Comment count reported by the source.
- Hacker News: 33, latest observation ; +33 over observed period since
- Lobsters: 13, latest observation ; +13 over observed period since
Aliases
| Source | External ID | URL |
|---|---|---|
| Hacker News | 50392733 | https://serce.me/posts/2026-10-30-how-hard-is-it-to-check-for-whitespace Read discussion |
| Lobsters | 1pmuy7 | https://serce.me/posts/2026-10-30-how-hard-is-it-to-check-for-whitespace Read discussion |