Skip to content

Commit b7b94fb

Browse files
authored
Merge pull request #91 from mattn/add-is-combining-width
Add IsCombiningWidth function
2 parents 6399b33 + 2c33cbf commit b7b94fb

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

.github/workflows/test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ jobs:
1212
matrix:
1313
os: [windows-latest, macos-latest, ubuntu-latest]
1414
go:
15+
- "1.26"
1516
- "1.25"
1617
- "1.24"
17-
- "1.23"
1818
runs-on: ${{ matrix.os }}
1919
steps:
20-
- uses: actions/checkout@v3
21-
- uses: actions/setup-go@v4
20+
- uses: actions/checkout@v4
21+
- uses: actions/setup-go@v5
2222
with:
2323
go-version: ${{ matrix.go }}
2424

@@ -27,4 +27,4 @@ jobs:
2727
- run: go test ./... -v -cover -coverprofile coverage.out
2828
- run: go test -bench . -benchmem
2929

30-
- uses: codecov/codecov-action@v3
30+
- uses: codecov/codecov-action@v5

runewidth.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ func IsAmbiguousWidth(r rune) bool {
316316
return inTables(r, private, ambiguous)
317317
}
318318

319+
// IsCombiningWidth returns whether is combining width or not.
320+
func IsCombiningWidth(r rune) bool {
321+
return inTable(r, combining)
322+
}
323+
319324
// IsNeutralWidth returns whether is neutral width or not.
320325
func IsNeutralWidth(r rune) bool {
321326
return inTable(r, neutral)

runewidth_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,27 @@ func TestIsNeutralWidth(t *testing.T) {
427427
}
428428
}
429429

430+
var iscombiningwidthtests = []struct {
431+
in rune
432+
out bool
433+
}{
434+
{'\u0300', true}, // COMBINING GRAVE ACCENT
435+
{'\uFE0F', true}, // VARIATION SELECTOR-16
436+
{'\uFE0E', true}, // VARIATION SELECTOR-15
437+
{'\u180B', true}, // MONGOLIAN FREE VARIATION SELECTOR ONE
438+
{'\U000E0100', true}, // VARIATION SELECTOR-17
439+
{'A', false},
440+
{'☆', false},
441+
}
442+
443+
func TestIsCombiningWidth(t *testing.T) {
444+
for _, tt := range iscombiningwidthtests {
445+
if out := IsCombiningWidth(tt.in); out != tt.out {
446+
t.Errorf("IsCombiningWidth(%q) = %v, want %v", tt.in, out, tt.out)
447+
}
448+
}
449+
}
450+
430451
func TestFillLeft(t *testing.T) {
431452
s := "あxいうえお"
432453
expected := " あxいうえお"

0 commit comments

Comments
 (0)