unicode-pitfalls
Installation
SKILL.md
Unicode pitfalls
Length has three meanings
For "π¨βπ©βπ§βπ¦" (family emoji):
| Measure | Value | Use for |
|---|---|---|
| Bytes (UTF-8) | 25 | Storage limits, network buffers |
| Code points | 7 | Almost never |
| Grapheme clusters | 1 | Anything a user sees or counts |
len() in Python and .length in JS give code points (JS gives UTF-16 units, so emoji count as 2). Neither matches what a user calls a character.
import regex
len(regex.findall(r'\X', s)) # grapheme clusters