优化字符串匹配

This commit is contained in:
zhangdeman committed 2021-03-12 13:53:06 +08:00
1 parent 5cb1fa20d5
commit c2bcab795d
1 file changed
+4 -3
+4 -3
View File
@@ -217,11 +217,12 @@ func (dj *DynamicJSON) extraSliceIndex(key string) (bool, int) {
// slice 至少是 [1] 格式
return false, 0
}
// 不用正则,直接字符串处理
strByte := []byte(key)
if string(strByte[0:1]) != "[" || string(strByte[len(strByte)-1:]) != "]" {
if !strings.HasPrefix(key, "[") || !strings.HasSuffix(key, "]") {
return false, 0
}
// 不用正则,直接字符串处理
strByte := []byte(key)
index, err := strconv.Atoi(string(strByte[1 : len(strByte)-1]))
if nil != err {
return false, 0
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.