fix(server): Improve quotes.go

This commit is contained in:
Myzel394 2024-10-15 14:20:57 +02:00
parent 0e18169a3f
commit f7f38454fd
No known key found for this signature in database
GPG Key ID: ED20A1D1D423AF3F

View File

@ -1,6 +1,9 @@
package utils
import "slices"
import (
"cmp"
"slices"
)
type quoteRange [2]int
@ -10,24 +13,24 @@ func (q quoteRange) IsCharInside(index int) bool {
type quoteRanges []quoteRange
func (q quoteRanges) IsCharInside(index int) bool {
_, found := slices.BinarySearchFunc(
func (q quoteRanges) IsIndexInsideQuotes(index int) bool {
return q.GetQuoteForIndex(index) != nil
}
func (q quoteRanges) GetQuoteForIndex(index int) *quoteRange {
index, found := slices.BinarySearchFunc(
q,
index,
func(current quoteRange, target int) int {
if target < current[0] {
return -1
}
if target > current[1] {
return 1
}
return 0
return cmp.Compare(target, current[0])
},
)
return found
if !found {
return nil
}
return &q[index]
}
func GetQuoteRanges(s string) quoteRanges {