From 01f382afeca388d41baff4ab673ca7d4924c9659 Mon Sep 17 00:00:00 2001 From: Roman Suvorov Date: Thu, 15 Sep 2022 20:04:04 +0300 Subject: [PATCH] change tail to prefix --- runewidth.go | 10 +++++----- runewidth_test.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/runewidth.go b/runewidth.go index c08c366..b3e6ed7 100644 --- a/runewidth.go +++ b/runewidth.go @@ -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 @@ -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 @@ -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 diff --git a/runewidth_test.go b/runewidth_test.go index 20fc9d5..d69fafa 100644 --- a/runewidth_test.go +++ b/runewidth_test.go @@ -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 { @@ -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 {