forked from External/ergo
be more lax about whitespace when parsing commands from clients
This commit is contained in:
parent
c1edddb9a1
commit
f9bf422ba7
1 changed files with 9 additions and 1 deletions
|
|
@ -3,6 +3,7 @@ package irc
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
|
@ -84,6 +85,10 @@ func ParseCommand(line string) (cmd editableCommand, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var (
|
||||
spacesExpr = regexp.MustCompile(` +`)
|
||||
)
|
||||
|
||||
func parseArg(line string) (arg string, rest string) {
|
||||
if line == "" {
|
||||
return
|
||||
|
|
@ -92,7 +97,7 @@ func parseArg(line string) (arg string, rest string) {
|
|||
if strings.HasPrefix(line, ":") {
|
||||
arg = line[1:]
|
||||
} else {
|
||||
parts := strings.SplitN(line, " ", 2)
|
||||
parts := spacesExpr.Split(line, 2)
|
||||
arg = parts[0]
|
||||
if len(parts) > 1 {
|
||||
rest = parts[1]
|
||||
|
|
@ -104,6 +109,9 @@ func parseArg(line string) (arg string, rest string) {
|
|||
func parseLine(line string) (command StringCode, args []string) {
|
||||
args = make([]string, 0)
|
||||
for arg, rest := parseArg(line); arg != ""; arg, rest = parseArg(rest) {
|
||||
if arg == "" {
|
||||
continue
|
||||
}
|
||||
args = append(args, arg)
|
||||
}
|
||||
if len(args) > 0 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue