Add tags.Extract() func

This commit is contained in:
Matt Baer
2018-10-16 20:33:34 -04:00
parent e5a5d63c6f
commit 73bffef9af
+22
View File
@@ -0,0 +1,22 @@
package tags
import (
"github.com/kylemcc/twitter-text-go/extract"
)
func Extract(body string) []string {
matches := extract.ExtractHashtags(body)
tags := map[string]bool{}
for i := range matches {
// Second value (whether or not there's a hashtag) ignored here, since
// we're only extracting hashtags.
ht, _ := matches[i].Hashtag()
tags[ht] = true
}
resTags := make([]string, 0)
for k := range tags {
resTags = append(resTags, k)
}
return resTags
}