feat: some experiments

This commit is contained in:
Max Richter
2025-09-26 17:32:16 +02:00
parent ea978b48f6
commit 8ca5152c3c
12 changed files with 147 additions and 66 deletions

46
template/slice.go Normal file
View 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,
}
}