diff options
author | 2021-08-20 12:26:56 +0200 | |
---|---|---|
committer | 2021-08-20 12:26:56 +0200 | |
commit | 4920229a3b6e1d7dde536bc9ff766542b05d935c (patch) | |
tree | a9423beccec5331c372f01eedf38949dfb171e9e /internal/util | |
parent | Text/status parsing fixes (#141) (diff) | |
download | gotosocial-4920229a3b6e1d7dde536bc9ff766542b05d935c.tar.xz |
Database updates (#144)
* start moving some database stuff around
* continue moving db stuff around
* more fiddling
* more updates
* and some more
* and yet more
* i broke SOMETHING but what, it's a mystery
* tidy up
* vendor ttlcache
* use ttlcache
* fix up some tests
* rename some stuff
* little reminder
* some more updates
Diffstat (limited to 'internal/util')
-rw-r--r-- | internal/util/statustools.go | 19 | ||||
-rw-r--r-- | internal/util/unique.go | 32 |
2 files changed, 35 insertions, 16 deletions
diff --git a/internal/util/statustools.go b/internal/util/statustools.go index ce5860c6d..4a89e60f6 100644 --- a/internal/util/statustools.go +++ b/internal/util/statustools.go @@ -34,7 +34,7 @@ func DeriveMentionsFromStatus(status string) []string { for _, m := range mentionFinderRegex.FindAllStringSubmatch(status, -1) { mentionedAccounts = append(mentionedAccounts, m[1]) } - return unique(mentionedAccounts) + return UniqueStrings(mentionedAccounts) } // DeriveHashtagsFromStatus takes a plaintext (ie., not html-formatted) status, @@ -46,7 +46,7 @@ func DeriveHashtagsFromStatus(status string) []string { for _, m := range HashtagFinderRegex.FindAllStringSubmatch(status, -1) { tags = append(tags, strings.TrimPrefix(m[1], "#")) } - return unique(tags) + return UniqueStrings(tags) } // DeriveEmojisFromStatus takes a plaintext (ie., not html-formatted) status, @@ -57,7 +57,7 @@ func DeriveEmojisFromStatus(status string) []string { for _, m := range emojiFinderRegex.FindAllStringSubmatch(status, -1) { emojis = append(emojis, m[1]) } - return unique(emojis) + return UniqueStrings(emojis) } // ExtractMentionParts extracts the username test_user and the domain example.org @@ -79,16 +79,3 @@ func ExtractMentionParts(mention string) (username, domain string, err error) { func IsMention(mention string) bool { return mentionNameRegex.MatchString(strings.ToLower(mention)) } - -// unique returns a deduplicated version of a given string slice. -func unique(s []string) []string { - keys := make(map[string]bool) - list := []string{} - for _, entry := range s { - if _, value := keys[entry]; !value { - keys[entry] = true - list = append(list, entry) - } - } - return list -} diff --git a/internal/util/unique.go b/internal/util/unique.go new file mode 100644 index 000000000..d679515d0 --- /dev/null +++ b/internal/util/unique.go @@ -0,0 +1,32 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +package util + +// UniqueStrings returns a deduplicated version of a given string slice. +func UniqueStrings(s []string) []string { + keys := make(map[string]bool) + list := []string{} + for _, entry := range s { + if _, value := keys[entry]; !value { + keys[entry] = true + list = append(list, entry) + } + } + return list +} |