move stuff back from nostr package to top level.

because otherwise the path must be specified as github.com/fiatjaf/go-nostr/nostr, which is annoying.
This commit is contained in:
fiatjaf
2022-11-04 08:22:12 -03:00
parent 3a6d6795e4
commit 329b8d44d2
12 changed files with 0 additions and 0 deletions

77
helpers.go Normal file
View File

@@ -0,0 +1,77 @@
package nostr
import (
"strings"
)
type StringList []string
type IntList []int
func (as StringList) Equals(bs StringList) bool {
if len(as) != len(bs) {
return false
}
for _, a := range as {
for _, b := range bs {
if b == a {
goto next
}
}
// didn't find a B that corresponded to the current A
return false
next:
continue
}
return true
}
func (as IntList) Equals(bs IntList) bool {
if len(as) != len(bs) {
return false
}
for _, a := range as {
for _, b := range bs {
if b == a {
goto next
}
}
// didn't find a B that corresponded to the current A
return false
next:
continue
}
return true
}
func (haystack StringList) Contains(needle string) bool {
for _, hay := range haystack {
if hay == needle {
return true
}
}
return false
}
func (haystack StringList) ContainsPrefixOf(needle string) bool {
for _, hay := range haystack {
if strings.HasPrefix(needle, hay) {
return true
}
}
return false
}
func (haystack IntList) Contains(needle int) bool {
for _, hay := range haystack {
if hay == needle {
return true
}
}
return false
}