Compare commits
2 Commits
2e620f7050
...
b8e1c2fca4
Author | SHA1 | Date |
---|---|---|
Lykin | b8e1c2fca4 | |
Lykin | cda10ed279 |
|
@ -51,7 +51,7 @@ Linux.</strong>
|
||||||
* Support import/export data.
|
* Support import/export data.
|
||||||
* Support publish/subscribe.
|
* Support publish/subscribe.
|
||||||
* Support import/export connection profile.
|
* Support import/export connection profile.
|
||||||
* Custom data encoder and decoder for value display.
|
* Custom data encoder and decoder for value display ([Here are the instructions](https://redis.tinycraft.cc/guide/custom-decoder/)).
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
* 支持导入/导出数据
|
* 支持导入/导出数据
|
||||||
* 支持发布订阅
|
* 支持发布订阅
|
||||||
* 支持导入/导出连接配置
|
* 支持导入/导出连接配置
|
||||||
* 自定义数据展示编码/解码
|
* 自定义数据展示编码/解码([这是操作指引](https://redis.tinycraft.cc/zh/guide/custom-decoder/))
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package strutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
sliceutil "tinyrdm/backend/utils/slice"
|
sliceutil "tinyrdm/backend/utils/slice"
|
||||||
|
@ -133,14 +132,32 @@ func AnyToString(value interface{}, prefix string, layer int) (s string) {
|
||||||
//}
|
//}
|
||||||
|
|
||||||
func SplitCmd(cmd string) []string {
|
func SplitCmd(cmd string) []string {
|
||||||
re := regexp.MustCompile(`'[^']+'|"[^"]+"|\S+`)
|
var result []string
|
||||||
args := re.FindAllString(cmd, -1)
|
var curStr strings.Builder
|
||||||
return sliceutil.FilterMap(args, func(i int) (string, bool) {
|
var preChar int32
|
||||||
arg := strings.Trim(args[i], "\"")
|
inQuotes := false
|
||||||
arg = strings.Trim(arg, "'")
|
|
||||||
if len(arg) <= 0 {
|
for _, char := range cmd {
|
||||||
return "", false
|
if char == '"' && preChar != '\\' {
|
||||||
|
inQuotes = !inQuotes
|
||||||
|
} else if char == ' ' && !inQuotes {
|
||||||
|
if curStr.Len() > 0 {
|
||||||
|
if part, e := strconv.Unquote(`"` + curStr.String() + `"`); e == nil {
|
||||||
|
result = append(result, part)
|
||||||
}
|
}
|
||||||
return arg, true
|
curStr.Reset()
|
||||||
})
|
}
|
||||||
|
} else {
|
||||||
|
curStr.WriteByte(byte(char))
|
||||||
|
}
|
||||||
|
preChar = char
|
||||||
|
}
|
||||||
|
|
||||||
|
if curStr.Len() > 0 {
|
||||||
|
if part, e := strconv.Unquote(`"` + curStr.String() + `"`); e == nil {
|
||||||
|
result = append(result, part)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue