From e8fe8d1a963e4ba8ef6a807babdcebbafc863e4d Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Tue, 13 Aug 2024 22:36:50 +0200 Subject: [PATCH] feat(utils): Add GetTrimIndex --- utils/strings.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/utils/strings.go b/utils/strings.go index 9243f53..50bf387 100644 --- a/utils/strings.go +++ b/utils/strings.go @@ -1,7 +1,22 @@ package utils -import "strings" +import ( + "regexp" + "strings" +) func IndexOffset(s string, search string, start int) int { 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] +}