mirror of
https://github.com/casdoor/casdoor.git
synced 2025-09-07 02:20:28 +08:00
feat: move to a more robust way of checking if element in slice (#4001)
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
|
||||
package util
|
||||
|
||||
import "sort"
|
||||
import "slices"
|
||||
|
||||
func DeleteVal(values []string, val string) []string {
|
||||
newValues := []string{}
|
||||
@@ -38,18 +38,8 @@ func ReplaceVal(values []string, oldVal string, newVal string) []string {
|
||||
return newValues
|
||||
}
|
||||
|
||||
func ContainsString(values []string, val string) bool {
|
||||
sort.Strings(values)
|
||||
return sort.SearchStrings(values, val) != len(values)
|
||||
}
|
||||
|
||||
func InSlice(slice []string, elem string) bool {
|
||||
for _, val := range slice {
|
||||
if val == elem {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(slice, elem)
|
||||
}
|
||||
|
||||
func ReturnAnyNotEmpty(strs ...string) string {
|
||||
|
@@ -54,10 +54,10 @@ func IsPhoneValid(phone string, countryCode string) bool {
|
||||
}
|
||||
|
||||
func IsPhoneAllowInRegin(countryCode string, allowRegions []string) bool {
|
||||
if ContainsString(allowRegions, "All") {
|
||||
if InSlice(allowRegions, "All") {
|
||||
return true
|
||||
}
|
||||
return ContainsString(allowRegions, countryCode)
|
||||
return InSlice(allowRegions, countryCode)
|
||||
}
|
||||
|
||||
func IsRegexp(s string) (bool, error) {
|
||||
|
Reference in New Issue
Block a user