3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-29 07:29:31 +01:00

Merge pull request #1070 from jesopo/isupport-equals

don't add trailing = to ISUPPORT tokens when value is empty string
This commit is contained in:
Shivaram Lingamneni 2020-05-31 21:30:17 -07:00 committed by GitHub
commit 44aebf44b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -15,7 +15,7 @@ const (
// List holds a list of ISUPPORT tokens // List holds a list of ISUPPORT tokens
type List struct { type List struct {
Tokens map[string]*string Tokens map[string]string
CachedReply [][]string CachedReply [][]string
} }
@ -27,26 +27,27 @@ func NewList() *List {
} }
func (il *List) Initialize() { func (il *List) Initialize() {
il.Tokens = make(map[string]*string) il.Tokens = make(map[string]string)
il.CachedReply = make([][]string, 0) il.CachedReply = make([][]string, 0)
} }
// Add adds an RPL_ISUPPORT token to our internal list // Add adds an RPL_ISUPPORT token to our internal list
func (il *List) Add(name string, value string) { func (il *List) Add(name string, value string) {
il.Tokens[name] = &value il.Tokens[name] = value
} }
// AddNoValue adds an RPL_ISUPPORT token that does not have a value // AddNoValue adds an RPL_ISUPPORT token that does not have a value
func (il *List) AddNoValue(name string) { func (il *List) AddNoValue(name string) {
il.Tokens[name] = nil il.Tokens[name] = ""
} }
// getTokenString gets the appropriate string for a token+value. // getTokenString gets the appropriate string for a token+value.
func getTokenString(name string, value *string) string { func getTokenString(name string, value string) string {
if value == nil { if len(value) == 0 {
return name return name
} }
return fmt.Sprintf("%s=%s", name, *value)
return fmt.Sprintf("%s=%s", name, value)
} }
// GetDifference returns the difference between two token lists. // GetDifference returns the difference between two token lists.
@ -68,7 +69,7 @@ func (il *List) GetDifference(newil *List) [][]string {
// append added tokens // append added tokens
for name, value := range newil.Tokens { for name, value := range newil.Tokens {
newval, exists := il.Tokens[name] newval, exists := il.Tokens[name]
if exists && ((value == nil && newval == nil) || (value != nil && newval != nil && *value == *newval)) { if exists && value == newval {
continue continue
} }