|
@@ -4,6 +4,7 @@
|
4
|
4
|
package irc
|
5
|
5
|
|
6
|
6
|
import "fmt"
|
|
7
|
+import "sort"
|
7
|
8
|
|
8
|
9
|
const isupportSupportedString = "are supported by this server"
|
9
|
10
|
|
|
@@ -41,9 +42,7 @@ func getTokenString(name string, value *string) string {
|
41
|
42
|
|
42
|
43
|
// GetDifference returns the difference between two token lists.
|
43
|
44
|
func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
|
44
|
|
- replies := make([][]string, 0)
|
45
|
|
- var length int // Length of the current cache
|
46
|
|
- var cache []string // Token list cache
|
|
45
|
+ var outTokens sort.StringSlice
|
47
|
46
|
|
48
|
47
|
// append removed tokens
|
49
|
48
|
for name := range il.Tokens {
|
|
@@ -54,32 +53,29 @@ func (il *ISupportList) GetDifference(newil *ISupportList) [][]string {
|
54
|
53
|
|
55
|
54
|
token := fmt.Sprintf("-%s", name)
|
56
|
55
|
|
57
|
|
- if len(token)+length <= maxLastArgLength {
|
58
|
|
- // account for the space separating tokens
|
59
|
|
- if len(cache) > 0 {
|
60
|
|
- length++
|
61
|
|
- }
|
62
|
|
- cache = append(cache, token)
|
63
|
|
- length += len(token)
|
64
|
|
- }
|
65
|
|
-
|
66
|
|
- if len(cache) == 13 || len(token)+length >= maxLastArgLength {
|
67
|
|
- cache = append(cache, isupportSupportedString)
|
68
|
|
- replies = append(replies, cache)
|
69
|
|
- cache = make([]string, 0)
|
70
|
|
- length = 0
|
71
|
|
- }
|
|
56
|
+ outTokens = append(outTokens, token)
|
72
|
57
|
}
|
73
|
58
|
|
74
|
59
|
// append added tokens
|
75
|
60
|
for name, value := range newil.Tokens {
|
76
|
61
|
newval, exists := il.Tokens[name]
|
77
|
|
- if exists && *value == *newval {
|
|
62
|
+ if exists && ((value == nil && newval == nil) || (value != nil && newval != nil && *value == *newval)) {
|
78
|
63
|
continue
|
79
|
64
|
}
|
80
|
65
|
|
81
|
66
|
token := getTokenString(name, value)
|
82
|
67
|
|
|
68
|
+ outTokens = append(outTokens, token)
|
|
69
|
+ }
|
|
70
|
+
|
|
71
|
+ sort.Sort(outTokens)
|
|
72
|
+
|
|
73
|
+ // create output list
|
|
74
|
+ replies := make([][]string, 0)
|
|
75
|
+ var length int // Length of the current cache
|
|
76
|
+ var cache []string // Token list cache
|
|
77
|
+
|
|
78
|
+ for _, token := range outTokens {
|
83
|
79
|
if len(token)+length <= maxLastArgLength {
|
84
|
80
|
// account for the space separating tokens
|
85
|
81
|
if len(cache) > 0 {
|
|
@@ -111,8 +107,15 @@ func (il *ISupportList) RegenerateCachedReply() {
|
111
|
107
|
var length int // Length of the current cache
|
112
|
108
|
var cache []string // Token list cache
|
113
|
109
|
|
114
|
|
- for name, value := range il.Tokens {
|
115
|
|
- token := getTokenString(name, value)
|
|
110
|
+ // make sure we get a sorted list of tokens, needed for tests and looks nice
|
|
111
|
+ var tokens sort.StringSlice
|
|
112
|
+ for name := range il.Tokens {
|
|
113
|
+ tokens = append(tokens, name)
|
|
114
|
+ }
|
|
115
|
+ sort.Sort(tokens)
|
|
116
|
+
|
|
117
|
+ for _, name := range tokens {
|
|
118
|
+ token := getTokenString(name, il.Tokens[name])
|
116
|
119
|
|
117
|
120
|
if len(token)+length <= maxLastArgLength {
|
118
|
121
|
// account for the space separating tokens
|