Improve docs and tests of utils package

This commit is contained in:
Daniel 2018-08-23 15:00:25 +02:00
parent 627939f7c6
commit c9f41a65af
2 changed files with 14 additions and 8 deletions

View file

@ -1,6 +1,7 @@
package utils
func StringInSlice(s string, a []string) bool {
// StringInSlice returns whether the given string is in the string slice.
func StringInSlice(a []string, s string) bool {
for _, entry := range a {
if entry == s {
return true
@ -9,6 +10,7 @@ func StringInSlice(s string, a []string) bool {
return false
}
// RemoveFromStringSlice removes the given string from the slice and returns a new slice.
func RemoveFromStringSlice(a []string, s string) []string {
for key, entry := range a {
if entry == s {
@ -19,12 +21,14 @@ func RemoveFromStringSlice(a []string, s string) []string {
return a
}
// DuplicateStrings returns a new copy of the given string slice.
func DuplicateStrings(a []string) []string {
b := make([]string, len(a))
copy(b, a)
return b
}
// StringSliceEqual returns whether the given string slices are equal.
func StringSliceEqual(a []string, b []string) bool {
if len(a) != len(b) {
return false
@ -37,6 +41,7 @@ func StringSliceEqual(a []string, b []string) bool {
return true
}
// DuplicateBytes returns a new copy of the given byte slice.
func DuplicateBytes(a []byte) []byte {
b := make([]byte, len(a))
copy(b, a)