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