mirror of
https://github.com/Myzel394/config-lsp.git
synced 2025-06-19 07:25:27 +02:00
feat(utils): Add GetTrimIndex
This commit is contained in:
parent
46a50c16a8
commit
e8fe8d1a96
@ -1,7 +1,22 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func IndexOffset(s string, search string, start int) int {
|
func IndexOffset(s string, search string, start int) int {
|
||||||
return strings.Index(s[start:], search) + start
|
return strings.Index(s[start:], search) + start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var trimIndexPattern = regexp.MustCompile(`^\s+(.+?)\s+`)
|
||||||
|
|
||||||
|
func GetTrimIndex(s string) []int {
|
||||||
|
indexes := trimIndexPattern.FindStringSubmatchIndex(s)
|
||||||
|
|
||||||
|
if indexes == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return indexes[2:4]
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user