Skip to content

Commit

Permalink
change tail to prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
tty2 committed Sep 15, 2022
1 parent f052c83 commit 01f382a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions runewidth.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ func (c *Condition) Truncate(s string, w int, tail string) string {
}

// TrimPrefix cuts w cells from the beginning of the `s`.
func (c *Condition) TrimPrefix(s string, w int, tail string) string {
func (c *Condition) TrimPrefix(s string, w int, prefix string) string {
if c.StringWidth(s) <= w {
return "" + tail
return prefix
}

var width int
Expand All @@ -240,7 +240,7 @@ func (c *Condition) TrimPrefix(s string, w int, tail string) string {
width += chWidth
}

return s[pos:] + tail
return prefix + s[pos:]
}

// Wrap return string wrapped with w cells
Expand Down Expand Up @@ -321,8 +321,8 @@ func Truncate(s string, w int, tail string) string {
}

// TrimPrefix cuts w cells from the beginning of the `s`.
func TrimPrefix(s string, w int, tail string) string {
return DefaultCondition.TrimPrefix(s, w, tail)
func TrimPrefix(s string, w int, prefix string) string {
return DefaultCondition.TrimPrefix(s, w, prefix)
}

// Wrap return string wrapped with w cells
Expand Down
4 changes: 2 additions & 2 deletions runewidth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func Test_TrimPrefix(t *testing.T) {
t.Run("ascii: with tail", func(t *testing.T) {
t.Parallel()
s := "source"
expected := "ce..."
expected := "...ce"

out := TrimPrefix(s, 4, "...")
if out != expected {
Expand All @@ -419,7 +419,7 @@ func Test_TrimPrefix(t *testing.T) {
t.Run("non ascii: with tail", func(t *testing.T) {
t.Parallel()
s := "あいうえお"
expected := "えお..."
expected := "...えお"

out := TrimPrefix(s, 6, "...")
if out != expected {
Expand Down

0 comments on commit 01f382a

Please # to comment.