Archived
Template
1
0

Initial commit

This commit is contained in:
uberswe
2021-12-12 14:56:13 +01:00
commit 0511f8fbca
1627 changed files with 773292 additions and 0 deletions

36
util/text.go Normal file
View File

@ -0,0 +1,36 @@
// Package util provides utility functions for various things such as strings
package util
import (
"fmt"
"net/url"
"strings"
)
func NL2BR(s string) string {
return strings.Replace(s, "\n", "<br>", -1)
}
func StringLinkToHTMLLink(s string) string {
s = strings.Replace(s, "\n", " \n ", -1)
for _, p := range strings.Split(s, " ") {
u, err := url.ParseRequestURI(p)
if err == nil && u.Scheme != "" {
s = strings.Replace(s, p, fmt.Sprintf("<a href=\"%s\">%s</a>", p, p), 1)
}
}
return strings.Replace(s, " \n ", "\n", -1)
}
func GetStringBetweenStrings(str string, start string, end string) (result string) {
s := strings.Index(str, start)
if s == -1 {
return
}
s += len(start)
e := strings.Index(str[s:], end)
if e == -1 {
return
}
return str[s : s+e]
}