47 lines
703 B
Go
47 lines
703 B
Go
package template
|
|
|
|
func NewSlice(s string) Slice {
|
|
return Slice{
|
|
source: &s,
|
|
start: 0,
|
|
end: len(s),
|
|
}
|
|
}
|
|
|
|
type Slice struct {
|
|
source *string
|
|
start, end int
|
|
}
|
|
|
|
func (s Slice) Chars() []byte {
|
|
return []byte((*s.source)[s.start:s.end])
|
|
}
|
|
|
|
func (s Slice) Len() int {
|
|
return s.end - s.start
|
|
}
|
|
|
|
func (s Slice) At(i int) byte {
|
|
return (*s.source)[s.start+i]
|
|
}
|
|
|
|
func SliceFromString(s string, start, end int) Slice {
|
|
return Slice{
|
|
source: &s,
|
|
start: start,
|
|
end: end,
|
|
}
|
|
}
|
|
|
|
func (s Slice) String() string {
|
|
return (*s.source)[s.start:s.end]
|
|
}
|
|
|
|
func (s Slice) Slice(start, end int) Slice {
|
|
return Slice{
|
|
source: s.source,
|
|
start: s.start + start,
|
|
end: s.start + end,
|
|
}
|
|
}
|