From: Eduardo Date: Thu, 28 Mar 2024 02:34:53 +0000 (+0100) Subject: useful string manipulation functions X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=0f3e41873605a71435c1b45ffc737c4220714a08;p=sylphiette-bot.git useful string manipulation functions get text after dash, get first line and get requested by --- diff --git a/bot.go b/bot.go index 31717cf..d4b4292 100644 --- a/bot.go +++ b/bot.go @@ -445,3 +445,25 @@ func replaceAllStrings(str string, old []string, new string) string { return str } + +func getTextAfterDash(s string) string { + dashIndex := strings.Index(s, "-") + if dashIndex != -1 { + return strings.TrimSpace(s[dashIndex+1:]) + } + return "" +} + +func getFirstLine(s string) string { + lines := strings.SplitN(s, "\n", 2) + return lines[0] +} + +func getRequestedBy(s string) string { + re := regexp.MustCompile(`(?i)Requested By:\s*(.*)`) + match := re.FindStringSubmatch(s) + if len(match) > 1 { + return strings.TrimSpace(match[1]) + } + return "???" +}