mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-18 23:15:26 +02:00
fix(server): Improve quotes.go
This commit is contained in:
parent
0e18169a3f
commit
f7f38454fd
@ -1,6 +1,9 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "slices"
|
import (
|
||||||
|
"cmp"
|
||||||
|
"slices"
|
||||||
|
)
|
||||||
|
|
||||||
type quoteRange [2]int
|
type quoteRange [2]int
|
||||||
|
|
||||||
@ -10,24 +13,24 @@ func (q quoteRange) IsCharInside(index int) bool {
|
|||||||
|
|
||||||
type quoteRanges []quoteRange
|
type quoteRanges []quoteRange
|
||||||
|
|
||||||
func (q quoteRanges) IsCharInside(index int) bool {
|
func (q quoteRanges) IsIndexInsideQuotes(index int) bool {
|
||||||
_, found := slices.BinarySearchFunc(
|
return q.GetQuoteForIndex(index) != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q quoteRanges) GetQuoteForIndex(index int) *quoteRange {
|
||||||
|
index, found := slices.BinarySearchFunc(
|
||||||
q,
|
q,
|
||||||
index,
|
index,
|
||||||
func(current quoteRange, target int) int {
|
func(current quoteRange, target int) int {
|
||||||
if target < current[0] {
|
return cmp.Compare(target, current[0])
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
if target > current[1] {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
return found
|
if !found {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &q[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetQuoteRanges(s string) quoteRanges {
|
func GetQuoteRanges(s string) quoteRanges {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user