From 41273a4d0725cd0f098184e01fee4e1a2516ae87 Mon Sep 17 00:00:00 2001
From: yuin
++//= = = = = = = = = = = = = = = = = = = = = = = =// diff --git a/text/segment.go b/text/segment.go index 3198d84..83c875b 100644 --- a/text/segment.go +++ b/text/segment.go @@ -44,12 +44,14 @@ func NewSegmentPadding(start, stop, n int) Segment { // Value returns a value of the segment. func (t *Segment) Value(buffer []byte) []byte { + var result []byte if t.Padding == 0 { - return buffer[t.Start:t.Stop] + result = buffer[t.Start:t.Stop] + } else { + result = make([]byte, 0, t.Padding+t.Stop-t.Start+1) + result = append(result, bytes.Repeat(space, t.Padding)...) + result = append(result, buffer[t.Start:t.Stop]...) } - result := make([]byte, 0, t.Padding+t.Stop-t.Start+1) - result = append(result, bytes.Repeat(space, t.Padding)...) - result = append(result, buffer[t.Start:t.Stop]...) if t.EOB && len(result) > 0 && result[len(result)-1] != '\n' { result = append(result, '\n') }+0 +