Skip to content

Commit

Permalink
fix: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Jan 23, 2025
1 parent 899593a commit c80c3b9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions ansi/truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ func TruncateLeft(s string, n int, prefix string) string {
return buf.String()
}

// ToCharRange takes start and stop byte positions and converts them to char
// positions.
// ByteToGraphemeRange takes start and stop byte positions and converts them to
// grapheme-aware char positions.
// You can use this with [Truncate], [TruncateLeft], and [Cut].
func ToCharRange(str string, byteStart, byteStop int) (charStart, charStop int) {
func ByteToGraphemeRange(str string, byteStart, byteStop int) (charStart, charStop int) {
bytePos, charPos := 0, 0
gr := uniseg.NewGraphemes(str)
for byteStart > bytePos {
Expand Down
4 changes: 2 additions & 2 deletions ansi/truncate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func TestCut(t *testing.T) {
}
}

func TestToCharRange(t *testing.T) {
func TestByteToGraphemeRange(t *testing.T) {
cases := []struct {
name string
feed [2]int
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestToCharRange(t *testing.T) {

for _, tt := range cases {
t.Run(tt.name, func(t *testing.T) {
charStart, charStop := ToCharRange(tt.input, tt.feed[0], tt.feed[1])
charStart, charStop := ByteToGraphemeRange(tt.input, tt.feed[0], tt.feed[1])
if expect := tt.expect[0]; expect != charStart {
t.Errorf("expected start to be %d, got %d", expect, charStart)
}
Expand Down

0 comments on commit c80c3b9

Please sign in to comment.