Added unicode support

Replaced strings with rune-slices, which capture unicode codepoints more
accurately.
This commit is contained in:
2024-11-18 10:41:50 -05:00
parent 805766a5ba
commit 8a1f1dc621
5 changed files with 8 additions and 8 deletions

View File

@@ -81,7 +81,7 @@ func pruneIndices(indices []MatchIndex) []MatchIndex {
// findAllMatches tries to find all matches of the regex represented by given start-state, with
// the given string
func findAllMatches(start *State, str string) []MatchIndex {
func findAllMatches(start *State, str []rune) []MatchIndex {
idx := 0
var matchFound bool
var matchIdx MatchIndex
@@ -104,7 +104,7 @@ func findAllMatches(start *State, str string) []MatchIndex {
// the next search should start from.
//
// Might return duplicates or overlapping indices, so care must be taken to prune the resulting array.
func findAllMatchesHelper(start *State, str string, offset int) (bool, MatchIndex, int) {
func findAllMatchesHelper(start *State, str []rune, offset int) (bool, MatchIndex, int) {
// Base case - exit if offset exceeds string's length
if offset > len(str) {
// The first value here shouldn't be used, because we should exit when the second return value is > than len(str)