Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 76a0460329
Fetching contributors…

Cannot retrieve contributors at this time

45 lines (32 sloc) 0.578 kb
package main
import (
"strings"
)
func FindURLs(text string, replacefunc func(string) string) string {
newtext := ""
i := 0
j := 0
for {
if i >= len(text) {
break
}
for !(strings.HasPrefix(text[j:], "http:") || strings.HasPrefix(text[j:], "https:")) && j < len(text) {
j++
}
newtext = newtext + text[i:j]
if j >= len(text) {
break
}
i = j
j = strings.IndexAny(text[i:], " ]>)")
if j < 0 {
j = len(text)
} else {
j += i
}
replaceurl := replacefunc(text[i:j])
newtext = newtext + replaceurl
i = j
}
return newtext
}
Jump to Line
Something went wrong with that request. Please try again.