feat(command): add command parsing
This commit is contained in:
41
commandParse.go
Normal file
41
commandParse.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func getTextMiddle(text, left, right string) string {
|
||||
start := 0
|
||||
if left != "" {
|
||||
idx := strings.Index(text, left)
|
||||
if idx == -1 {
|
||||
return ""
|
||||
}
|
||||
start = idx + len(left)
|
||||
}
|
||||
|
||||
if right == "" {
|
||||
if start > len(text) {
|
||||
return ""
|
||||
}
|
||||
return text[start:]
|
||||
}
|
||||
|
||||
endIdx := strings.Index(text[start:], right)
|
||||
if endIdx == -1 {
|
||||
return ""
|
||||
}
|
||||
return text[start : start+endIdx]
|
||||
}
|
||||
|
||||
func getCommand(content string) string {
|
||||
return getTextMiddle(content, "[", "]")
|
||||
}
|
||||
|
||||
func parseCommand(content, cmdType string) string {
|
||||
return getTextMiddle(content, "<" + cmdType + ">", "</" + cmdType + ">")
|
||||
}
|
||||
|
||||
func executeCommand(input string) error {
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user