From 73bffef9af8c418e6fdb99fcf2f0b1ff17113780 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 16 Oct 2018 20:33:34 -0400 Subject: [PATCH] Add tags.Extract() func --- tags/tags.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tags/tags.go diff --git a/tags/tags.go b/tags/tags.go new file mode 100644 index 0000000..b980eb5 --- /dev/null +++ b/tags/tags.go @@ -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 +}