Modified genRange() so that it can work on ints and runes
This commit is contained in:
10
misc.go
10
misc.go
@@ -15,6 +15,12 @@ var LPAREN_CHAR rune = 0xF0004 // Parentheses in regex are concatenated with thi
|
|||||||
var RPAREN_CHAR rune = 0xF0005
|
var RPAREN_CHAR rune = 0xF0005
|
||||||
var NONCAPLPAREN_CHAR rune = 0xF0006 // Represents a non-capturing group's LPAREN
|
var NONCAPLPAREN_CHAR rune = 0xF0006 // Represents a non-capturing group's LPAREN
|
||||||
var ESC_BACKSLASH rune = 0xF0007 // Represents an escaped backslash
|
var ESC_BACKSLASH rune = 0xF0007 // Represents an escaped backslash
|
||||||
|
var CHAR_RANGE rune = 0xF0008 // Represents a character range
|
||||||
|
|
||||||
|
// An interface for int and rune, which are identical
|
||||||
|
type character interface {
|
||||||
|
int | rune
|
||||||
|
}
|
||||||
|
|
||||||
// Returns true if str[idx] and str[idx-1] are separated by a word boundary.
|
// Returns true if str[idx] and str[idx-1] are separated by a word boundary.
|
||||||
func isWordBoundary(str []rune, idx int) bool {
|
func isWordBoundary(str []rune, idx int) bool {
|
||||||
@@ -109,8 +115,8 @@ func Reduce[T any](slc []T, fn func(T, T) T) T {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate numbers in a range - start (inclusive) to end (exclusive)
|
// Generate numbers in a range - start (inclusive) to end (exclusive)
|
||||||
func genRange(start, end int) []int {
|
func genRange[T character](start, end T) []T {
|
||||||
toRet := make([]int, end-start)
|
toRet := make([]T, end-start)
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
toRet[i-start] = i
|
toRet[i-start] = i
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user