33
44package oauth2
55
6- import (
7- "strings"
8- )
9-
106type Arguments []string
117
12- // Matches performs an case-insensitive, out-of-order check that the items
8+ // Matches performs an case-sensitive, out-of-order check that the items
9+ // provided exist and equal all of the args in arguments.
10+ func (r Arguments ) Matches (items ... string ) bool {
11+ if len (r ) != len (items ) {
12+ return false
13+ }
14+
15+ found := make (map [string ]bool )
16+ for _ , item := range items {
17+ if ! StringInSlice (item , r ) {
18+ return false
19+ }
20+ found [item ] = true
21+ }
22+
23+ return len (found ) == len (r )
24+ }
25+
26+ // MatchesFold performs an case-insensitive, out-of-order check that the items
1327// provided exist and equal all of the args in arguments.
1428// Note:
1529// - Providing a list that includes duplicate string-case items will return not
1630// matched.
17- func (r Arguments ) Matches (items ... string ) bool {
31+ func (r Arguments ) MatchesFold (items ... string ) bool {
1832 if len (r ) != len (items ) {
1933 return false
2034 }
2135
2236 found := make (map [string ]bool )
2337 for _ , item := range items {
24- if ! StringInSlice (item , r ) {
38+ if ! StringInSliceFold (item , r ) {
2539 return false
2640 }
2741 found [item ] = true
@@ -30,7 +44,7 @@ func (r Arguments) Matches(items ...string) bool {
3044 return len (found ) == len (r )
3145}
3246
33- // Has checks, in a case-insensitive manner, that all of the items
47+ // Has checks, in a case-sensitive manner, that all of the items
3448// provided exists in arguments.
3549func (r Arguments ) Has (items ... string ) bool {
3650 for _ , item := range items {
@@ -42,7 +56,19 @@ func (r Arguments) Has(items ...string) bool {
4256 return true
4357}
4458
45- // HasOneOf checks, in a case-insensitive manner, that one of the items
59+ // HasFold checks, in a case-insensitive manner, that all of the items
60+ // provided exists in arguments.
61+ func (r Arguments ) HasFold (items ... string ) bool {
62+ for _ , item := range items {
63+ if ! StringInSliceFold (item , r ) {
64+ return false
65+ }
66+ }
67+
68+ return true
69+ }
70+
71+ // HasOneOf checks, in a case-sensitive manner, that one of the items
4672// provided exists in arguments.
4773func (r Arguments ) HasOneOf (items ... string ) bool {
4874 for _ , item := range items {
@@ -54,9 +80,16 @@ func (r Arguments) HasOneOf(items ...string) bool {
5480 return false
5581}
5682
57- // Deprecated: Use ExactOne, Matches or MatchesExact
58- func (r Arguments ) Exact (name string ) bool {
59- return name == strings .Join (r , " " )
83+ // HasOneOfFold checks, in a case-sensitive manner, that one of the items
84+ // provided exists in arguments.
85+ func (r Arguments ) HasOneOfFold (items ... string ) bool {
86+ for _ , item := range items {
87+ if StringInSliceFold (item , r ) {
88+ return true
89+ }
90+ }
91+
92+ return false
6093}
6194
6295// ExactOne checks, by string case, that a single argument equals the provided
0 commit comments