You've already forked golang-base-project
Adds godoc comments
This commit is contained in:
24
text/html.go
Normal file
24
text/html.go
Normal file
@ -0,0 +1,24 @@
|
||||
package text
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Nl2Br converts \n to HTML <br> tags
|
||||
func Nl2Br(s string) string {
|
||||
return strings.Replace(s, "\n", "<br>", -1)
|
||||
}
|
||||
|
||||
// LinkToHTMLLink converts regular links to HTML links
|
||||
func LinkToHTMLLink(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)
|
||||
}
|
15
text/random.go
Normal file
15
text/random.go
Normal file
@ -0,0 +1,15 @@
|
||||
package text
|
||||
|
||||
import "math/rand"
|
||||
|
||||
// RandomString generates a random string of n length. Based on https://stackoverflow.com/a/22892986/1260548
|
||||
func RandomString(n int) string {
|
||||
// remove vowels to make it less likely to generate something offensive
|
||||
var letters = []rune("bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ")
|
||||
|
||||
b := make([]rune, n)
|
||||
for i := range b {
|
||||
b[i] = letters[rand.Intn(len(letters))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
17
text/segment.go
Normal file
17
text/segment.go
Normal file
@ -0,0 +1,17 @@
|
||||
package text
|
||||
|
||||
import "strings"
|
||||
|
||||
// BetweenStrings returns a string between the starting and ending string or an empty string if none could be found
|
||||
func BetweenStrings(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]
|
||||
}
|
Reference in New Issue
Block a user