mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
treewide: make explicit calls to JSONDict.Remove() and JSONDict.RemoveIgnoreCase
This commit is contained in:
+26
-1
@@ -42,11 +42,36 @@ func NewFloat(val float64) *JSONFloat {
|
||||
return &JSONFloat{data: val}
|
||||
}
|
||||
|
||||
func NewBool(val bool) *JSONBool {
|
||||
if val {
|
||||
return JSONTrue
|
||||
}
|
||||
return JSONFalse
|
||||
}
|
||||
|
||||
func (this *JSONDict) Set(key string, value JSONObject) {
|
||||
this.data[key] = value
|
||||
}
|
||||
|
||||
func (this *JSONDict) Remove(key string, caseSensitive bool) bool {
|
||||
func (this *JSONDict) Remove(key string) bool {
|
||||
return this.remove(key, true)
|
||||
}
|
||||
|
||||
func (this *JSONDict) RemoveIgnoreCase(key string) bool {
|
||||
someRemoved := false
|
||||
for {
|
||||
removed := this.remove(key, false)
|
||||
if !removed {
|
||||
break
|
||||
}
|
||||
if !someRemoved {
|
||||
someRemoved = true
|
||||
}
|
||||
}
|
||||
return someRemoved
|
||||
}
|
||||
|
||||
func (this *JSONDict) remove(key string, caseSensitive bool) bool {
|
||||
_, rk, ok := dictGet(this.data, key, caseSensitive)
|
||||
if ok {
|
||||
delete(this.data, rk)
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package jsonutils
|
||||
|
||||
func (this *JSONString) Length() int {
|
||||
return len(this.data)
|
||||
}
|
||||
|
||||
func (this *JSONDict) Length() int {
|
||||
return len(this.data)
|
||||
}
|
||||
|
||||
func (this *JSONArray) Length() int {
|
||||
return len(this.data)
|
||||
}
|
||||
Reference in New Issue
Block a user