From 20fbd20994c4a3969162a4acae24c574078e2994 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 9 Dec 2024 01:05:26 -0500 Subject: [PATCH] Added helper function to expand a slice to a given length --- misc.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/misc.go b/misc.go index 7ce3210..8d920f2 100644 --- a/misc.go +++ b/misc.go @@ -10,7 +10,9 @@ var digitChars = []rune{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} var wordChars = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") var LBRACKET rune = 0xF0000 var RBRACKET rune = 0xF0001 -var ANY_CHAR rune = 0xF0002 // Represents any character - used for states where the allChars flag is on. +var ANY_CHAR rune = 0xF0002 // Represents any character - used for states where the allChars flag is on. +var LPAREN_CHAR rune = 0xF0003 // Parentheses in regex are concatenated with this - it acts as a pseudio-parentheses +var RPAREN_CHAR rune = 0xF0004 // Returns true if str[idx] and str[idx-1] are separated by a word boundary. func isWordBoundary(str []rune, idx int) bool { @@ -121,3 +123,10 @@ func genRange(start, end int) []int { func allCases(r rune) []rune { return []rune{unicode.ToLower(r), unicode.ToUpper(r), unicode.ToTitle(r)} } + +// Expands a slice to the given length +func expandSlice[T any](slc []T, newSize int) []T { + toRet := make([]T, newSize) + copy(toRet, slc) + return toRet +}