A modification-free API for Minecraft utilizing log parsing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

71 lines
1.1 KiB

package commands
type SpaceTokenizer struct {
Input string
}
func (t *SpaceTokenizer) NextToken() string {
if len(t.Input) == 0 {
return ""
}
ch := t.Input[0]
if ch == '"' {
// Scan until closing quote or end of string
for i := 1; i < len(t.Input); i++ {
if t.Input[i] == '"' && t.Input[i-1] != '\\' {
ret := t.Input[1:i]
if i+2 < len(t.Input) {
t.Input = t.Input[i+2:]
} else {
t.Input = ""
}
return ret
}
}
} else {
for i := 0; i < len(t.Input); i++ {
if t.Input[i] == ' ' {
ret := t.Input[0:i]
if i+1 < len(t.Input) {
t.Input = t.Input[i+1:]
} else {
t.Input = ""
}
return ret
}
}
}
ret := t.Input
t.Input = ""
return ret
}
func (t *SpaceTokenizer) Empty() bool {
return t.Input == ""
}
func NewSpaceTokenizer(input string) *SpaceTokenizer {
return &SpaceTokenizer{Input: input}
}
func ParseCommandArguments(command string) []string {
tokenizer := NewSpaceTokenizer(command)
arguments := make([]string, 0)
for {
if tokenizer.Empty() {
break
}
arguments = append(arguments, tokenizer.NextToken())
}
return arguments
}