How hard is it to check for whitespace?
theanonymousone
125 points
33 comments
November 06, 2026
Related Discussions
Found 5 related stories in 38.3ms across 3,874 title embeddings via pgvector HNSW
- Let Me Ch... alxgsv · 184 pts · November 02, 2026 · 42% similar
- Code Smells of Desperation (2023) sammatilda · 15 pts · November 12, 2026 · 40% similar
- Writing correct software is hard and math alone won’t help us (2016) AriFordsham · 361 pts · November 12, 2026 · 38% similar
- Automatic Checking of Compiler Correctness with E-Graphs g0xA52A2A · 66 pts · November 17, 2026 · 38% similar
- Test/verification technique effectiveness with Astra luu · 91 pts · November 16, 2026 · 36% similar
Discussion Highlights (9 comments)
austin-cheney
The \s character class in JavaScript regular expressions includes 25 characters. I don’t know if that perfectly matches the Unicode list of 25 characters, but it does make identifying white space simplistic. White space characters are challenging to differentiate in human readable text, but JavaScript makes that perfectly clear to humans by splitting a string on every character, which is helpful for debugging.
adornKey
With font.color = white even an ordinary "W" could count as whitespace... Something to remember if you see whitespace with an extraordinary width out there in the wild...
LoganDark
Whitespace depends on the context. For example, you could have characters that are not counted as whitespace in Unicode, but end up rendering as whitespace when displayed in a particular context. The only real way to check for this is to actually try to render it and see what happens. There are some other ways to approximate it, like checking the font that you use for rendering, or the bounds of the glyph, or other things like that, but the only way to really know for sure in all cases is to just render it and see what happens.
efilife
This code is very simple but I still don't really get it. Why is the hashing needed and how is it faster than a regex? Can someone smarter than me explain?
smallstepforman
With bitmasks, if they just assumed bit 5 (whatever) as zero=whitespace, they would have saved billions of cpu cycles per device per day. With 32 bit unicode, that gives you 32 unique whitespace chars. Should have got guys that grew up with the 8-bit micros to write up a spec.
pixelbeat__
I think horizontal white spacing should be distinguished, as that's what most care about with splitting etc. Have a look at how GNU coreutils classifies each type of spacing (in a cross platform consistent way) at https://github.com/coreutils/coreutils/blob/master/src%2Fsys...
eviks
> For instance, ZERO WIDTH SPACE (U+200B) isn't a whitespace character at all. Despite the name, it's a format character that can indicate a word or line break opportunity without adding a visible gap. that's what happens when you throw a lot of garbage in, mix it up and forget to clean (piece of trivia - this was a space char many years ago; another one - the Braille whitespace char is unitechnically not whitespace) > So even the assumption that whitespace must look empty isn't always true. indeed, another obvious fail of this classification ("naming is hard") > not frozen in time, and is constantly evolving unfortunatly the evolution is freezing, so such issues remain unfixed. Here is a few emojis as a consolation prize instead!
Whitespace
I was here before the first character was carved into stone and I will be here when the last photon is emitted. I'm also available via: @gmail.com (please don't write code with `@whitespace` as I get a lot of GitHub notifications)
exacube
If you want to learn how that magic multiplier value was derived, look up how to derive Perfect Hash Functions for a known set of values. I'm not sure which method was used for this specific set of values, but from googling it's seen advances in the past decade.