aboutsummaryrefslogtreecommitdiffstats
path: root/skate
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-05-12 23:21:49 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-05-12 23:21:49 +0200
commit368bf739ac91e2b604897460d1993cfdfab4928c (patch)
treead43ba7cde70b2083e080e552498f14e3fa8c650 /skate
parent71f8167681218a74bee98f0bb7ff0123581ccb49 (diff)
downloadrefcat-368bf739ac91e2b604897460d1993cfdfab4928c.tar.gz
refcat-368bf739ac91e2b604897460d1993cfdfab4928c.zip
cleanup: we require two indices
Diffstat (limited to 'skate')
-rw-r--r--skate/url.go15
1 files changed, 8 insertions, 7 deletions
diff --git a/skate/url.go b/skate/url.go
index b104651..f81b1d2 100644
--- a/skate/url.go
+++ b/skate/url.go
@@ -21,17 +21,17 @@ var (
// http://agingmind.utdallas.edu/facedb/view/neutral-faces.doi:10.3758/BF03206543.
// http://10.3386/w20634https://doi.org/10.3386/w20634
func SanitizeURL(s string) string {
- var (
- // seems to only be about 15% of total time spent
- index = suffixarray.New([]byte(s))
- indices = index.Lookup([]byte("http"), -1)
- )
if !strings.HasPrefix(s, "http") && !strings.HasPrefix(s, "ftp") {
- s = sanitizeRaw(s, index)
+ s = sanitizeRaw(s)
if s == "" {
return s
}
}
+ var (
+ // seems to only be about 15% of total time spent
+ index = suffixarray.New([]byte(s))
+ indices = index.Lookup([]byte("http"), -1)
+ )
if len(indices) > 1 {
s = s[0:indices[1]] // only use the first
s = strings.TrimRight(s, ":")
@@ -60,7 +60,8 @@ func SanitizeURL(s string) string {
return s
}
-func sanitizeRaw(s string, index *suffixarray.Index) string {
+func sanitizeRaw(s string) string {
+ index := suffixarray.New([]byte(s))
if len(s) < 4 {
return ""
}