String width is the sum of its code point widths
All 31 scenarios hold
Emoji and CJK render two columns wide, so mixed-script strings are wider than their character count. A null or empty string has width zero.
expected outcome
broken scenario
| Scenario | Text | Width? |
|---|---|---|
| ASCII single letter | A | 1 |
| ASCII word | Hello | 5 |
| ASCII numbers | 123 | 3 |
| CJK single character | 中 | 2 |
| CJK two characters | 你好 | 4 |
| CJK four characters | 你好世界 | 8 |
| Japanese hiragana | こんにちは | 10 |
| Japanese hiragana with kanji | こんにちは世界 | 14 |
| Korean short greeting | 안녕 | 4 |
| Korean greeting | 안녕하세요 | 10 |
| Emoji grinning face | 😀 | 2 |
| Emoji waving hand | 👋 | 2 |
| Emoji coffee | ☕ | 2 |
| Mixed ASCII and emoji | Hello 👋 World | 14 |
| Mixed text with emoji | Café ☕ tastes good | 19 |
| Scandinavian æ | æ | 1 |
| Scandinavian ø repeated | øøø | 3 |
| Scandinavian å repeated | ååå | 3 |
| Accented word naïve | naïve | 5 |
| Accented word résumé | résumé | 6 |
| Greek letters with spaces | α β γ | 5 |
| Greek greeting | Γεια σου κόσμε | 14 |
| Cyrillic greeting | Привет мир | 10 |
| Arabic greeting | مرحبا بالعالم | 13 |
| Hebrew greeting | שלום עולם | 9 |
| Mathematical symbols | ∑ ∏ ∫ √ | 7 |
| Box drawing characters | ┌─┐│ │└─┘ | 9 |
| Currency symbols | $€£¥₹ | 5 |
| Quotation marks | «»""''—– | 8 |
| Null string | 0 | |
| Empty string | “” | 0 |