package text

import (
	
	
)

var space = []byte(" ")
A Segment struct holds information about source positions.
Start is a start position of the segment.
Stop is a stop position of the segment. This value should be excluded.
Padding is a padding length of the segment.
NewSegment return a new Segment.
func (,  int) Segment {
	return Segment{
		Start:   ,
		Stop:    ,
		Padding: 0,
	}
}
NewSegmentPadding returns a new Segment with the given padding.
func (, ,  int) Segment {
	return Segment{
		Start:   ,
		Stop:    ,
		Padding: ,
	}
}
Value returns a value of the segment.
func ( *Segment) ( []byte) []byte {
	if .Padding == 0 {
		return [.Start:.Stop]
	}
	 := make([]byte, 0, .Padding+.Stop-.Start+1)
	 = append(, bytes.Repeat(space, .Padding)...)
	return append(, [.Start:.Stop]...)
}
Len returns a length of the segment.
func ( *Segment) () int {
	return .Stop - .Start + .Padding
}
Between returns a segment between this segment and the given segment.
func ( *Segment) ( Segment) Segment {
	if .Stop != .Stop {
		panic("invalid state")
	}
	return NewSegmentPadding(
		.Start,
		.Start,
		.Padding-.Padding,
	)
}
IsEmpty returns true if this segment is empty, otherwise false.
func ( *Segment) () bool {
	return .Start >= .Stop && .Padding == 0
}
TrimRightSpace returns a new segment by slicing off all trailing space characters.
func ( *Segment) ( []byte) Segment {
	 := [.Start:.Stop]
	 := util.TrimRightSpaceLength()
	if  == len() {
		return NewSegment(.Start, .Start)
	}
	return NewSegmentPadding(.Start, .Stop-, .Padding)
}
TrimLeftSpace returns a new segment by slicing off all leading space characters including padding.
func ( *Segment) ( []byte) Segment {
	 := [.Start:.Stop]
	 := util.TrimLeftSpaceLength()
	return NewSegment(.Start+, .Stop)
}
TrimLeftSpaceWidth returns a new segment by slicing off leading space characters until the given width.
func ( *Segment) ( int,  []byte) Segment {
	 := .Padding
	for ;  > 0; -- {
		if  == 0 {
			break
		}
		--
	}
	if  == 0 {
		return NewSegmentPadding(.Start, .Stop, )
	}
	 := [.Start:.Stop]
	 := .Start
	for ,  := range  {
		if  >= .Stop-1 ||  <= 0 {
			break
		}
		if  == ' ' {
			--
		} else if  == '\t' {
			 -= 4
		} else {
			break
		}
		++
	}
	if  < 0 {
		 =  * -1
	}
	return NewSegmentPadding(, .Stop, )
}
WithStart returns a new Segment with same value except Start.
func ( *Segment) ( int) Segment {
	return NewSegmentPadding(, .Stop, .Padding)
}
WithStop returns a new Segment with same value except Stop.
func ( *Segment) ( int) Segment {
	return NewSegmentPadding(.Start, , .Padding)
}
ConcatPadding concats the padding to the given slice.
func ( *Segment) ( []byte) []byte {
	if .Padding > 0 {
		return append(, bytes.Repeat(space, .Padding)...)
	}
	return 
}
Segments is a collection of the Segment.
type Segments struct {
	values []Segment
}
NewSegments return a new Segments.
func () *Segments {
	return &Segments{
		values: nil,
	}
}
Append appends the given segment after the tail of the collection.
func ( *Segments) ( Segment) {
	if .values == nil {
		.values = make([]Segment, 0, 20)
	}
	.values = append(.values, )
}
AppendAll appends all elements of given segments after the tail of the collection.
func ( *Segments) ( []Segment) {
	if .values == nil {
		.values = make([]Segment, 0, 20)
	}
	.values = append(.values, ...)
}
Len returns the length of the collection.
func ( *Segments) () int {
	if .values == nil {
		return 0
	}
	return len(.values)
}
At returns a segment at the given index.
func ( *Segments) ( int) Segment {
	return .values[]
}
Set sets the given Segment.
func ( *Segments) ( int,  Segment) {
	.values[] = 
}
SetSliced replace the collection with a subsliced value.
func ( *Segments) (,  int) {
	.values = .values[:]
}
Sliced returns a subslice of the collection.
func ( *Segments) (,  int) []Segment {
	return .values[:]
}
Clear delete all element of the collection.
func ( *Segments) () {
	.values = nil
}
Unshift insert the given Segment to head of the collection.
func ( *Segments) ( Segment) {
	.values = append(.values[0:1], .values[0:]...)
	.values[0] =