This commit is contained in:
bluepython508 committed 2026-10-22 12:27:19 +01:00
1 parent 3530afb854
commit 6903fcff27
2146 files changed
+112256 -190703

No files matched your search

+15 -25
View File
@@ -88,21 +88,6 @@ func (v *Value) Format() {
v.UpdateOffsets()
}
// Range iterates through a Value in depth-first order and
// calls f for each value (including the root value).
// It stops iteration when f returns false.
func (v *Value) Range(f func(v *Value) bool) bool {
if !f(v) {
return false
}
if comp, ok := v.Value.(composite); ok {
return comp.rangeValues(func(v2 *Value) bool {
return v2.Range(f)
})
}
return true
}
// normalize performs simple normalization changes. In particular, it:
// - normalizes strings,
// - normalizes empty objects and arrays as simply {} or [],
@@ -129,15 +114,16 @@ func (v *Value) normalize() bool {
// If there is only whitespace between the name and colon,
// or between the value and comma, then remove the whitespace.
v2.rangeValues(func(v *Value) bool {
if !v.AfterExtra.hasComment() {
v.AfterExtra = nil
for v3 := range v2.allValues() {
if !v3.AfterExtra.hasComment() {
v3.AfterExtra = nil
}
return true
})
}
// Normalize all sub-values.
v2.rangeValues((*Value).normalize)
for v3 := range v2.allValues() {
v3.normalize()
}
}
return true
}
@@ -583,7 +569,9 @@ func (v *Value) alignObjectValues() bool {
// Recursively align all sub-objects.
if comp, ok := v.Value.(composite); ok {
comp.rangeValues((*Value).alignObjectValues)
for v2 := range comp.allValues() {
v2.alignObjectValues()
}
}
return true
}
@@ -593,9 +581,11 @@ func (v Value) hasNewline(checkTopLevelExtra bool) bool {
return true
}
if comp, ok := v.Value.(composite); ok {
return !comp.rangeValues(func(v *Value) bool {
return !v.hasNewline(true)
})
for v := range comp.allValues() {
if v.hasNewline(true) {
return true
}
}
}
return false
}