package helper import ( "regexp" ) func removeTrailingWhitespace(str string) string { re := regexp.MustCompile(`(^\s+)|(\s+$)`) return re.ReplaceAllString(str, "") } func removeDuplicateWhitespace(str string) string { re := regexp.MustCompile(`\s{2,}`) return re.ReplaceAllString(str, " ") } func removeNewlines(str string) string { re := regexp.MustCompile(`\n+`) return re.ReplaceAllString(str, "") } func removeDuplicateNewlines(str string) string { re := regexp.MustCompile(`\n{2,}`) return re.ReplaceAllString(str, "\n") } func CleanTitle(title string) string { title = removeDuplicateWhitespace(title) title = removeNewlines(title) return removeTrailingWhitespace(title) } func CleanContents(contents string) string { contents = removeDuplicateWhitespace(contents) contents = removeDuplicateNewlines(contents) return removeTrailingWhitespace(contents) }