Hacker News | 📄 原文链接 | 2026-11-11 收录

判断一个字符是不是空白,能有多难

来源:serce.me — 2026-10-30

📋 概述

作者在 Guava 里看到一段远比 c == ' ' 复杂的空白判断代码,顺着挖下去发现三层复杂度:Unicode 定义 25 个空白字符,但 Java、Python、JavaScript 三家各有一套——Java 排除不换行空格,Python 认 29 个(多出文件分隔符这类控制字符),JavaScript 反过来认 U+FEFF 却不认 U+0085;Unicode 自己还在改(U+180E 曾被移出空白集);最后为了让判断够快,Guava 用了一个完美哈希:乘 1682554634 再右移 27 位取索引,查一张 32 字符的表。

🔑 核心要点

💡 金句

I do feel that these write-ups are becoming increasingly rare in the AI-first world, where there's rarely a reason to peek under the hood of a function as simple as isWhitespace.
← 返回 Hacker News 首页