Skip to content

Commit 01f382a

Browse files
committed
change tail to prefix
1 parent f052c83 commit 01f382a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Diff for: runewidth.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ func (c *Condition) Truncate(s string, w int, tail string) string {
215215
}
216216

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

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

243-
return s[pos:] + tail
243+
return prefix + s[pos:]
244244
}
245245

246246
// Wrap return string wrapped with w cells
@@ -321,8 +321,8 @@ func Truncate(s string, w int, tail string) string {
321321
}
322322

323323
// TrimPrefix cuts w cells from the beginning of the `s`.
324-
func TrimPrefix(s string, w int, tail string) string {
325-
return DefaultCondition.TrimPrefix(s, w, tail)
324+
func TrimPrefix(s string, w int, prefix string) string {
325+
return DefaultCondition.TrimPrefix(s, w, prefix)
326326
}
327327

328328
// Wrap return string wrapped with w cells

Diff for: runewidth_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ func Test_TrimPrefix(t *testing.T) {
397397
t.Run("ascii: with tail", func(t *testing.T) {
398398
t.Parallel()
399399
s := "source"
400-
expected := "ce..."
400+
expected := "...ce"
401401

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

424424
out := TrimPrefix(s, 6, "...")
425425
if out != expected {

0 commit comments

Comments
 (0)