Commit 103888f
committed
fix: use codepoint count for std.format width padding
Motivation:
`std.format("%5s", "😀")` produced 3 spaces + emoji because width was
computed using String.length (UTF-16 code units), counting the surrogate
pair as 2. go-jsonnet and Python both count codepoints, yielding 4 spaces.
Modification:
Replace `.length` with `.codePointCount(0, _.length)` in the `widen`
function's missingWidth calculation. This is consistent with the precision
truncation in the same file which already uses codePointCount.
Result:
Width padding now counts supplementary characters as 1 codepoint, matching
go-jsonnet and Python behavior. ASCII-only strings (the common case) are
unaffected since codePointCount == length for BMP text.1 parent 16e868e commit 103888f
3 files changed
Lines changed: 24 additions & 1 deletion
File tree
- sjsonnet
- src/sjsonnet
- test/resources/new_test_suite
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
290 | 293 | | |
291 | 294 | | |
292 | 295 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
0 commit comments