feat: some experiments
This commit is contained in:
46
template/slice.go
Normal file
46
template/slice.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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,
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user