mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-13 07:29:30 +01:00
rewrite parseLine to be much saner about utf8
This commit is contained in:
parent
e409bcec99
commit
a30bb540e9
@ -96,35 +96,17 @@ var (
|
|||||||
spacesExpr = regexp.MustCompile(` +`)
|
spacesExpr = regexp.MustCompile(` +`)
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseArg(line string) (arg string, rest string) {
|
func parseLine(line string) (StringCode, []string) {
|
||||||
if line == "" {
|
var parts []string
|
||||||
return
|
if colonIndex := strings.IndexRune(line, ':'); colonIndex >= 0 {
|
||||||
}
|
lastArg := line[colonIndex+len(":"):]
|
||||||
|
line = line[:colonIndex-len(" ")]
|
||||||
if strings.HasPrefix(line, ":") {
|
parts = append(spacesExpr.Split(line, -1), lastArg)
|
||||||
arg = line[1:]
|
|
||||||
} else {
|
} else {
|
||||||
parts := spacesExpr.Split(line, 2)
|
parts = spacesExpr.Split(line, -1)
|
||||||
arg = parts[0]
|
|
||||||
if len(parts) > 1 {
|
|
||||||
rest = parts[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
return StringCode(strings.ToUpper(parts[0])), parts[1:]
|
||||||
command, args = StringCode(strings.ToUpper(args[0])), args[1:]
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// <command> [args...]
|
// <command> [args...]
|
||||||
|
Loading…
Reference in New Issue
Block a user