2024-09-21 09:34:05 +02:00

68 lines
1.1 KiB
Go

package matchparser
import "slices"
func (m Match) GetEntryByCursor(cursor uint32) *MatchEntry {
index, found := slices.BinarySearchFunc(
m.Entries,
cursor,
func(current *MatchEntry, target uint32) int {
if target < current.Start.Character {
return 1
}
if target > current.End.Character {
return -1
}
return 0
},
)
if !found {
return nil
}
entry := m.Entries[index]
return entry
}
func (c MatchCriteria) IsCursorBetween(cursor uint32) bool {
return cursor >= c.Start.Character && cursor <= c.End.Character
}
func (e MatchEntry) GetValueByCursor(cursor uint32) *MatchValue {
if e.Values == nil {
return nil
}
index, found := slices.BinarySearchFunc(
e.Values.Values,
cursor,
func(current *MatchValue, target uint32) int {
if target < current.Start.Character {
return 1
}
if target > current.End.Character {
return -1
}
return 0
},
)
if !found {
return nil
}
value := e.Values.Values[index]
return value
}
func (v MatchValues) IsCursorBetween(cursor uint32) bool {
return cursor >= v.Start.Character && cursor <= v.End.Character
}