use rune literals for ease of reading

This commit is contained in:
Liam Stanley 2017-11-30 10:23:52 -05:00
parent a20d84603a
commit c2601da083
7 changed files with 36 additions and 36 deletions

View File

@ -389,7 +389,7 @@ func handleISUPPORT(c *Client, e Event) {
c.state.Lock()
// Skip the first parameter, as it's our nickname.
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]) {
c.state.serverOptions[e.Params[i]] = ""

14
cap.go
View File

@ -375,11 +375,11 @@ func handleTags(c *Client, e Event) {
}
const (
prefixTag byte = 0x40 // @
prefixTagValue byte = 0x3D // =
prefixUserTag byte = 0x2B // +
tagSeparator byte = 0x3B // ;
maxTagLength int = 511 // 510 + @ and " " (space), though space usually not included.
prefixTag byte = '@'
prefixTagValue byte = '='
prefixUserTag byte = '+'
tagSeparator byte = ';'
maxTagLength int = 511 // 510 + @ and " " (space), though space usually not included.
)
// 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++ {
// 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
}
}
@ -631,7 +631,7 @@ func validTag(name string) bool {
func validTagValue(value string) bool {
for i := 0; i < len(value); i++ {
// 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
}
}

View File

@ -58,7 +58,7 @@ func decodeCTCP(e *Event) *CTCPEvent {
if s < 0 {
for i := 0; i < len(text); i++ {
// 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
}
}
@ -74,7 +74,7 @@ func decodeCTCP(e *Event) *CTCPEvent {
// Loop through checking the tag first.
for i := 0; i < s; i++ {
// 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
}
}
@ -168,7 +168,7 @@ func (c *CTCP) parseCMD(cmd string) string {
for i := 0; i < len(cmd); i++ {
// 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 ""
}
}

View File

@ -11,8 +11,8 @@ import (
)
const (
eventSpace byte = 0x20 // Separator.
maxLength = 510 // Maximum length is 510 (2 for line endings).
eventSpace byte = ' ' // Separator.
maxLength = 510 // Maximum length is 510 (2 for line endings).
)
// cutCRFunc is used to trim CR characters from prefixes/messages.
@ -256,7 +256,7 @@ func (e *Event) Bytes() []byte {
// Strip newlines and carriage returns.
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:]...)
i-- // Decrease the index so we can pick up where we left off.
}
@ -432,9 +432,9 @@ func (e *Event) StripAction() string {
}
const (
messagePrefix byte = 0x3A // ":" -- prefix or last argument
prefixIdent byte = 0x21 // "!" -- username
prefixHost byte = 0x40 // "@" -- hostname
messagePrefix byte = ':' // Prefix or last argument.
prefixIdent byte = '!' // Username.
prefixHost byte = '@' // Hostname.
)
// Source represents the sender of an IRC event, see RFC1459 section 2.3.1.

View File

@ -12,8 +12,8 @@ import (
)
const (
fmtOpenChar = 0x7B // {
fmtCloseChar = 0x7D // }
fmtOpenChar = '{'
fmtCloseChar = '}'
)
var fmtColors = map[string]int{
@ -113,7 +113,7 @@ func Fmt(text string) string {
if last > -1 {
// 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
continue
}
@ -127,10 +127,10 @@ func Fmt(text string) string {
// See Fmt() for more information.
func TrimFmt(text string) string {
for color := range fmtColors {
text = strings.Replace(text, "{"+color+"}", "", -1)
text = strings.Replace(text, string(fmtOpenChar)+color+string(fmtCloseChar), "", -1)
}
for code := range fmtCodes {
text = strings.Replace(text, "{"+code+"}", "", -1)
text = strings.Replace(text, string(fmtOpenChar)+code+string(fmtCloseChar), "", -1)
}
return text
@ -177,7 +177,7 @@ func IsValidChannel(channel string) bool {
// #, +, !<channelid>, or &
// 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
}
@ -186,14 +186,14 @@ func IsValidChannel(channel string) bool {
// 1 (prefix) + 5 (id) + 1 (+, channel name)
// On some networks, this may be extended with ISUPPORT capabilities,
// however this is extremely uncommon.
if channel[0] == 0x21 {
if channel[0] == '!' {
if len(channel) < 7 {
return false
}
// check for valid ID
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
}
}
@ -226,13 +226,13 @@ func IsValidNick(nick string) bool {
// Check the first index. Some characters aren't allowed for the first
// index of an IRC nickname.
if nick[0] < 0x41 || nick[0] > 0x7D {
if nick[0] < 'A' || nick[0] > '}' {
// a-z, A-Z, and _\[]{}^|
return false
}
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 _\[]{}^|
return false
}
@ -264,7 +264,7 @@ func IsValidUser(name string) bool {
name = ToRFC1459(name)
// "~" is prepended (commonly) if there was no ident server response.
if name[0] == 0x7E {
if name[0] == '~' {
// Means name only contained "~".
if len(name) < 2 {
return false
@ -274,12 +274,12 @@ func IsValidUser(name string) bool {
}
// 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
}
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 _\[]{}^|
return false
}

View File

@ -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
// external/internal handler maps.
func (c *Caller) cuidToID(input string) (cmd, uid string) {
i := strings.IndexByte(input, 0x3A)
i := strings.IndexByte(input, ':')
if i < 0 {
return "", ""
}

View File

@ -206,11 +206,11 @@ func (c *CModes) Parse(flags string, args []string) (out []CMode) {
var argCount int
for i := 0; i < len(flags); i++ {
if flags[i] == 0x2B {
if flags[i] == '+' {
add = true
continue
}
if flags[i] == 0x2D {
if flags[i] == '-' {
add = false
continue
}
@ -265,7 +265,7 @@ func IsValidChannelMode(raw string) bool {
for i := 0; i < len(raw); i++ {
// 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
}
}
@ -279,7 +279,7 @@ func isValidUserPrefix(raw string) bool {
return false
}
if raw[0] != 0x28 { // (.
if raw[0] != '(' {
return false
}
@ -288,7 +288,7 @@ func isValidUserPrefix(raw string) bool {
// Skip the first one as we know it's (.
for i := 1; i < len(raw); i++ {
if raw[i] == 0x29 { // ).
if raw[i] == ')' {
passedKeys = true
continue
}