diff --git a/irc/commands.go b/irc/commands.go index 6ccbe35d..8229d217 100644 --- a/irc/commands.go +++ b/irc/commands.go @@ -80,7 +80,7 @@ func (command *BaseCommand) SetCode(code StringCode) { } func ParseCommand(line string) (cmd editableCommand, err error) { - code, args := parseLine(line) + code, args := ParseLine(line) constructor := parseCommandFuncs[code] if constructor == nil { cmd = NewUnknownCommand(args) @@ -97,19 +97,33 @@ var ( spacesExpr = regexp.MustCompile(` +`) ) -func parseLine(line string) (StringCode, []string) { - var parts []string - if colonIndex := strings.IndexRune(line, ':'); colonIndex >= 0 { - lastArg := norm.NFC.String(line[colonIndex+len(":"):]) - line = strings.TrimRight(line[:colonIndex], " ") - line = norm.NFKC.String(line) - parts = append(spacesExpr.Split(line, -1), lastArg) - } else { - line = strings.TrimRight(line, " ") - line = norm.NFKC.String(line) - parts = spacesExpr.Split(line, -1) +func splitArg(line string) (arg string, rest string) { + parts := spacesExpr.Split(line, 2) + if len(parts) > 0 { + arg = parts[0] } - return StringCode(strings.ToUpper(parts[0])), parts[1:] + if len(parts) > 1 { + rest = parts[1] + } + return +} + +func ParseLine(line string) (command StringCode, args []string) { + args = make([]string, 0) + if strings.HasPrefix(line, ":") { + _, line = splitArg(line) + } + arg, line := splitArg(line) + command = StringCode(strings.ToUpper(arg)) + for len(line) > 0 { + if strings.HasPrefix(line, ":") { + args = append(args, norm.NFC.String(line[len(":"):])) + break + } + arg, line = splitArg(line) + args = append(args, norm.NFKC.String(arg)) + } + return } // [args...] diff --git a/irc/constants.go b/irc/constants.go index d1904d0e..83e73efb 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -23,7 +23,7 @@ var ( ) const ( - SEM_VER = "ergonomadic-1.2.10" + SEM_VER = "ergonomadic-1.2.11" CRLF = "\r\n" MAX_REPLY_LEN = 512 - len(CRLF)