treewide: make explicit calls to JSONDict.Remove() and JSONDict.RemoveIgnoreCase

This commit is contained in:
Yousong Zhou
2018-08-09 04:30:56 +00:00
parent fd352dbdbb
commit 1bf9036c83
9 changed files with 52 additions and 13 deletions
+26 -1
View File
@@ -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
View File
@@ -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)
}