1

Use library implementation of Contains function

This commit is contained in:
stephenmk 2023-02-01 18:57:35 -06:00
parent 8281301869
commit 3b420f8b6c
No known key found for this signature in database
GPG Key ID: B6DA730DB06235F1

View File

@ -9,6 +9,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"golang.org/x/exp/slices"
) )
const ( const (
@ -116,7 +118,7 @@ type dbKanjiList []dbKanji
func (kanji *dbKanji) addTags(tags ...string) { func (kanji *dbKanji) addTags(tags ...string) {
for _, tag := range tags { for _, tag := range tags {
if !hasString(tag, kanji.Tags) { if !slices.Contains(kanji.Tags, tag) {
kanji.Tags = append(kanji.Tags, tag) kanji.Tags = append(kanji.Tags, tag)
} }
} }
@ -245,7 +247,7 @@ func writeDb(outputPath string, index dbIndex, recordData map[string]dbRecordLis
func appendStringUnique(target []string, source ...string) []string { func appendStringUnique(target []string, source ...string) []string {
for _, str := range source { for _, str := range source {
if !hasString(str, target) { if !slices.Contains(target, str) {
target = append(target, str) target = append(target, str)
} }
} }
@ -253,16 +255,6 @@ func appendStringUnique(target []string, source ...string) []string {
return target return target
} }
func hasString(needle string, haystack []string) bool {
for _, value := range haystack {
if needle == value {
return true
}
}
return false
}
func intersection(s1, s2 []string) []string { func intersection(s1, s2 []string) []string {
s := []string{} s := []string{}
m := make(map[string]bool) m := make(map[string]bool)