use rune literals for ease of reading
This commit is contained in:
parent
a20d84603a
commit
c2601da083
|
@ -389,7 +389,7 @@ func handleISUPPORT(c *Client, e Event) {
|
||||||
c.state.Lock()
|
c.state.Lock()
|
||||||
// Skip the first parameter, as it's our nickname.
|
// Skip the first parameter, as it's our nickname.
|
||||||
for i := 1; i < len(e.Params); i++ {
|
for i := 1; i < len(e.Params); i++ {
|
||||||
j := strings.IndexByte(e.Params[i], 0x3D) // =
|
j := strings.IndexByte(e.Params[i], '=')
|
||||||
|
|
||||||
if j < 1 || (j+1) == len(e.Params[i]) {
|
if j < 1 || (j+1) == len(e.Params[i]) {
|
||||||
c.state.serverOptions[e.Params[i]] = ""
|
c.state.serverOptions[e.Params[i]] = ""
|
||||||
|
|
14
cap.go
14
cap.go
|
@ -375,11 +375,11 @@ func handleTags(c *Client, e Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
prefixTag byte = 0x40 // @
|
prefixTag byte = '@'
|
||||||
prefixTagValue byte = 0x3D // =
|
prefixTagValue byte = '='
|
||||||
prefixUserTag byte = 0x2B // +
|
prefixUserTag byte = '+'
|
||||||
tagSeparator byte = 0x3B // ;
|
tagSeparator byte = ';'
|
||||||
maxTagLength int = 511 // 510 + @ and " " (space), though space usually not included.
|
maxTagLength int = 511 // 510 + @ and " " (space), though space usually not included.
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tags represents the key-value pairs in IRCv3 message tags. The map contains
|
// Tags represents the key-value pairs in IRCv3 message tags. The map contains
|
||||||
|
@ -618,7 +618,7 @@ func validTag(name string) bool {
|
||||||
|
|
||||||
for i := 0; i < len(name); i++ {
|
for i := 0; i < len(name); i++ {
|
||||||
// A-Z, a-z, 0-9, -/._
|
// A-Z, a-z, 0-9, -/._
|
||||||
if (name[i] < 0x41 || name[i] > 0x5A) && (name[i] < 0x61 || name[i] > 0x7A) && (name[i] < 0x2D || name[i] > 0x39) && name[i] != 0x5F {
|
if (name[i] < 'A' || name[i] > 'Z') && (name[i] < 'a' || name[i] > 'z') && (name[i] < '-' || name[i] > '9') && name[i] != '_' {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -631,7 +631,7 @@ func validTag(name string) bool {
|
||||||
func validTagValue(value string) bool {
|
func validTagValue(value string) bool {
|
||||||
for i := 0; i < len(value); i++ {
|
for i := 0; i < len(value); i++ {
|
||||||
// Don't allow any invisible chars within the tag, or semicolons.
|
// Don't allow any invisible chars within the tag, or semicolons.
|
||||||
if value[i] < 0x21 || value[i] > 0x7E || value[i] == 0x3B {
|
if value[i] < '!' || value[i] > '~' || value[i] == ';' {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
ctcp.go
6
ctcp.go
|
@ -58,7 +58,7 @@ func decodeCTCP(e *Event) *CTCPEvent {
|
||||||
if s < 0 {
|
if s < 0 {
|
||||||
for i := 0; i < len(text); i++ {
|
for i := 0; i < len(text); i++ {
|
||||||
// Check for A-Z, 0-9.
|
// Check for A-Z, 0-9.
|
||||||
if (text[i] < 0x41 || text[i] > 0x5A) && (text[i] < 0x30 || text[i] > 0x39) {
|
if (text[i] < 'A' || text[i] > 'Z') && (text[i] < '0' || text[i] > '9') {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func decodeCTCP(e *Event) *CTCPEvent {
|
||||||
// Loop through checking the tag first.
|
// Loop through checking the tag first.
|
||||||
for i := 0; i < s; i++ {
|
for i := 0; i < s; i++ {
|
||||||
// Check for A-Z, 0-9.
|
// Check for A-Z, 0-9.
|
||||||
if (text[i] < 0x41 || text[i] > 0x5A) && (text[i] < 0x30 || text[i] > 0x39) {
|
if (text[i] < 'A' || text[i] > 'Z') && (text[i] < '0' || text[i] > '9') {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ func (c *CTCP) parseCMD(cmd string) string {
|
||||||
|
|
||||||
for i := 0; i < len(cmd); i++ {
|
for i := 0; i < len(cmd); i++ {
|
||||||
// Check for A-Z, 0-9.
|
// Check for A-Z, 0-9.
|
||||||
if (cmd[i] < 0x41 || cmd[i] > 0x5A) && (cmd[i] < 0x30 || cmd[i] > 0x39) {
|
if (cmd[i] < 'A' || cmd[i] > 'Z') && (cmd[i] < '0' || cmd[i] > '9') {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
event.go
12
event.go
|
@ -11,8 +11,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
eventSpace byte = 0x20 // Separator.
|
eventSpace byte = ' ' // Separator.
|
||||||
maxLength = 510 // Maximum length is 510 (2 for line endings).
|
maxLength = 510 // Maximum length is 510 (2 for line endings).
|
||||||
)
|
)
|
||||||
|
|
||||||
// cutCRFunc is used to trim CR characters from prefixes/messages.
|
// cutCRFunc is used to trim CR characters from prefixes/messages.
|
||||||
|
@ -256,7 +256,7 @@ func (e *Event) Bytes() []byte {
|
||||||
|
|
||||||
// Strip newlines and carriage returns.
|
// Strip newlines and carriage returns.
|
||||||
for i := 0; i < len(out); i++ {
|
for i := 0; i < len(out); i++ {
|
||||||
if out[i] == 0x0A || out[i] == 0x0D {
|
if out[i] == '\n' || out[i] == '\r' {
|
||||||
out = append(out[:i], out[i+1:]...)
|
out = append(out[:i], out[i+1:]...)
|
||||||
i-- // Decrease the index so we can pick up where we left off.
|
i-- // Decrease the index so we can pick up where we left off.
|
||||||
}
|
}
|
||||||
|
@ -432,9 +432,9 @@ func (e *Event) StripAction() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
messagePrefix byte = 0x3A // ":" -- prefix or last argument
|
messagePrefix byte = ':' // Prefix or last argument.
|
||||||
prefixIdent byte = 0x21 // "!" -- username
|
prefixIdent byte = '!' // Username.
|
||||||
prefixHost byte = 0x40 // "@" -- hostname
|
prefixHost byte = '@' // Hostname.
|
||||||
)
|
)
|
||||||
|
|
||||||
// Source represents the sender of an IRC event, see RFC1459 section 2.3.1.
|
// Source represents the sender of an IRC event, see RFC1459 section 2.3.1.
|
||||||
|
|
26
format.go
26
format.go
|
@ -12,8 +12,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
fmtOpenChar = 0x7B // {
|
fmtOpenChar = '{'
|
||||||
fmtCloseChar = 0x7D // }
|
fmtCloseChar = '}'
|
||||||
)
|
)
|
||||||
|
|
||||||
var fmtColors = map[string]int{
|
var fmtColors = map[string]int{
|
||||||
|
@ -113,7 +113,7 @@ func Fmt(text string) string {
|
||||||
|
|
||||||
if last > -1 {
|
if last > -1 {
|
||||||
// A-Z, a-z, and ","
|
// A-Z, a-z, and ","
|
||||||
if text[i] != 0x2c && (text[i] <= 0x41 || text[i] >= 0x5a) && (text[i] <= 0x61 || text[i] >= 0x7a) {
|
if text[i] != ',' && (text[i] <= 'A' || text[i] >= 'Z') && (text[i] <= 'a' || text[i] >= 'z') {
|
||||||
last = -1
|
last = -1
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -127,10 +127,10 @@ func Fmt(text string) string {
|
||||||
// See Fmt() for more information.
|
// See Fmt() for more information.
|
||||||
func TrimFmt(text string) string {
|
func TrimFmt(text string) string {
|
||||||
for color := range fmtColors {
|
for color := range fmtColors {
|
||||||
text = strings.Replace(text, "{"+color+"}", "", -1)
|
text = strings.Replace(text, string(fmtOpenChar)+color+string(fmtCloseChar), "", -1)
|
||||||
}
|
}
|
||||||
for code := range fmtCodes {
|
for code := range fmtCodes {
|
||||||
text = strings.Replace(text, "{"+code+"}", "", -1)
|
text = strings.Replace(text, string(fmtOpenChar)+code+string(fmtCloseChar), "", -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
@ -177,7 +177,7 @@ func IsValidChannel(channel string) bool {
|
||||||
|
|
||||||
// #, +, !<channelid>, or &
|
// #, +, !<channelid>, or &
|
||||||
// Including "*" in the prefix list, as this is commonly used (e.g. ZNC)
|
// Including "*" in the prefix list, as this is commonly used (e.g. ZNC)
|
||||||
if bytes.IndexByte([]byte{0x21, 0x23, 0x26, 0x2A, 0x2B}, channel[0]) == -1 {
|
if bytes.IndexByte([]byte{'!', '#', '&', '*', '+'}, channel[0]) == -1 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,14 +186,14 @@ func IsValidChannel(channel string) bool {
|
||||||
// 1 (prefix) + 5 (id) + 1 (+, channel name)
|
// 1 (prefix) + 5 (id) + 1 (+, channel name)
|
||||||
// On some networks, this may be extended with ISUPPORT capabilities,
|
// On some networks, this may be extended with ISUPPORT capabilities,
|
||||||
// however this is extremely uncommon.
|
// however this is extremely uncommon.
|
||||||
if channel[0] == 0x21 {
|
if channel[0] == '!' {
|
||||||
if len(channel) < 7 {
|
if len(channel) < 7 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for valid ID
|
// check for valid ID
|
||||||
for i := 1; i < 6; i++ {
|
for i := 1; i < 6; i++ {
|
||||||
if (channel[i] < 0x30 || channel[i] > 0x39) && (channel[i] < 0x41 || channel[i] > 0x5A) {
|
if (channel[i] < '0' || channel[i] > '9') && (channel[i] < 'A' || channel[i] > 'Z') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,13 +226,13 @@ func IsValidNick(nick string) bool {
|
||||||
|
|
||||||
// Check the first index. Some characters aren't allowed for the first
|
// Check the first index. Some characters aren't allowed for the first
|
||||||
// index of an IRC nickname.
|
// index of an IRC nickname.
|
||||||
if nick[0] < 0x41 || nick[0] > 0x7D {
|
if nick[0] < 'A' || nick[0] > '}' {
|
||||||
// a-z, A-Z, and _\[]{}^|
|
// a-z, A-Z, and _\[]{}^|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 1; i < len(nick); i++ {
|
for i := 1; i < len(nick); i++ {
|
||||||
if (nick[i] < 0x41 || nick[i] > 0x7D) && (nick[i] < 0x30 || nick[i] > 0x39) && nick[i] != 0x2D {
|
if (nick[i] < 'A' || nick[i] > '}') && (nick[i] < '0' || nick[i] > '9') && nick[i] != '-' {
|
||||||
// a-z, A-Z, 0-9, -, and _\[]{}^|
|
// a-z, A-Z, 0-9, -, and _\[]{}^|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ func IsValidUser(name string) bool {
|
||||||
name = ToRFC1459(name)
|
name = ToRFC1459(name)
|
||||||
|
|
||||||
// "~" is prepended (commonly) if there was no ident server response.
|
// "~" is prepended (commonly) if there was no ident server response.
|
||||||
if name[0] == 0x7E {
|
if name[0] == '~' {
|
||||||
// Means name only contained "~".
|
// Means name only contained "~".
|
||||||
if len(name) < 2 {
|
if len(name) < 2 {
|
||||||
return false
|
return false
|
||||||
|
@ -274,12 +274,12 @@ func IsValidUser(name string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if the first index is alphanumeric.
|
// Check to see if the first index is alphanumeric.
|
||||||
if (name[0] < 0x41 || name[0] > 0x4A) && (name[0] < 0x61 || name[0] > 0x7A) && (name[0] < 0x30 || name[0] > 0x39) {
|
if (name[0] < 'A' || name[0] > 'J') && (name[0] < 'a' || name[0] > 'z') && (name[0] < '0' || name[0] > '9') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 1; i < len(name); i++ {
|
for i := 1; i < len(name); i++ {
|
||||||
if (name[i] < 0x41 || name[i] > 0x7D) && (name[i] < 0x30 || name[i] > 0x39) && name[i] != 0x2D && name[i] != 0x2E {
|
if (name[i] < 'A' || name[i] > '}') && (name[i] < '0' || name[i] > '9') && name[i] != '-' && name[i] != '.' {
|
||||||
// a-z, A-Z, 0-9, -, and _\[]{}^|
|
// a-z, A-Z, 0-9, -, and _\[]{}^|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,7 +144,7 @@ func (c *Caller) cuid(cmd string, n int) (cuid, uid string) {
|
||||||
// cuidToID allows easy mapping between a generated cuid and the caller
|
// cuidToID allows easy mapping between a generated cuid and the caller
|
||||||
// external/internal handler maps.
|
// external/internal handler maps.
|
||||||
func (c *Caller) cuidToID(input string) (cmd, uid string) {
|
func (c *Caller) cuidToID(input string) (cmd, uid string) {
|
||||||
i := strings.IndexByte(input, 0x3A)
|
i := strings.IndexByte(input, ':')
|
||||||
if i < 0 {
|
if i < 0 {
|
||||||
return "", ""
|
return "", ""
|
||||||
}
|
}
|
||||||
|
|
10
modes.go
10
modes.go
|
@ -206,11 +206,11 @@ func (c *CModes) Parse(flags string, args []string) (out []CMode) {
|
||||||
var argCount int
|
var argCount int
|
||||||
|
|
||||||
for i := 0; i < len(flags); i++ {
|
for i := 0; i < len(flags); i++ {
|
||||||
if flags[i] == 0x2B {
|
if flags[i] == '+' {
|
||||||
add = true
|
add = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if flags[i] == 0x2D {
|
if flags[i] == '-' {
|
||||||
add = false
|
add = false
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ func IsValidChannelMode(raw string) bool {
|
||||||
|
|
||||||
for i := 0; i < len(raw); i++ {
|
for i := 0; i < len(raw); i++ {
|
||||||
// Allowed are: ",", A-Z and a-z.
|
// Allowed are: ",", A-Z and a-z.
|
||||||
if raw[i] != 0x2C && (raw[i] < 0x41 || raw[i] > 0x5A) && (raw[i] < 0x61 || raw[i] > 0x7A) {
|
if raw[i] != ',' && (raw[i] < 'A' || raw[i] > 'Z') && (raw[i] < 'a' || raw[i] > 'z') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ func isValidUserPrefix(raw string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if raw[0] != 0x28 { // (.
|
if raw[0] != '(' {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ func isValidUserPrefix(raw string) bool {
|
||||||
|
|
||||||
// Skip the first one as we know it's (.
|
// Skip the first one as we know it's (.
|
||||||
for i := 1; i < len(raw); i++ {
|
for i := 1; i < len(raw); i++ {
|
||||||
if raw[i] == 0x29 { // ).
|
if raw[i] == ')' {
|
||||||
passedKeys = true
|
passedKeys = true
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue