Skip to content

Commit 73bffef

Browse files
committed
Add tags.Extract() func
1 parent e5a5d63 commit 73bffef

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tags/tags.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package tags
2+
3+
import (
4+
"github.com/kylemcc/twitter-text-go/extract"
5+
)
6+
7+
func Extract(body string) []string {
8+
matches := extract.ExtractHashtags(body)
9+
tags := map[string]bool{}
10+
for i := range matches {
11+
// Second value (whether or not there's a hashtag) ignored here, since
12+
// we're only extracting hashtags.
13+
ht, _ := matches[i].Hashtag()
14+
tags[ht] = true
15+
}
16+
17+
resTags := make([]string, 0)
18+
for k := range tags {
19+
resTags = append(resTags, k)
20+
}
21+
return resTags
22+
}

0 commit comments

Comments
 (0)