MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / pruneMissingMapKeys

Function pruneMissingMapKeys

internal/config/config.go:1887–1916  ·  view source on GitHub ↗
(dstMap, srcMap *yaml.Node)

Source from the content-addressed store, hash-verified

1885}
1886
1887func pruneMissingMapKeys(dstMap, srcMap *yaml.Node) {
1888 if dstMap == nil || srcMap == nil || dstMap.Kind != yaml.MappingNode || srcMap.Kind != yaml.MappingNode {
1889 return
1890 }
1891 keep := make(map[string]struct{}, len(srcMap.Content)/2)
1892 for i := 0; i+1 < len(srcMap.Content); i += 2 {
1893 keyNode := srcMap.Content[i]
1894 if keyNode == nil {
1895 continue
1896 }
1897 key := strings.TrimSpace(keyNode.Value)
1898 if key == "" {
1899 continue
1900 }
1901 keep[key] = struct{}{}
1902 }
1903 for i := 0; i+1 < len(dstMap.Content); {
1904 keyNode := dstMap.Content[i]
1905 if keyNode == nil {
1906 i += 2
1907 continue
1908 }
1909 key := strings.TrimSpace(keyNode.Value)
1910 if _, ok := keep[key]; !ok {
1911 dstMap.Content = append(dstMap.Content[:i], dstMap.Content[i+2:]...)
1912 continue
1913 }
1914 i += 2
1915 }
1916}
1917
1918// normalizeCollectionNodeStyles forces YAML collections to use block notation, keeping
1919// lists and maps readable. Empty sequences retain flow style ([]) so empty list markers

Callers 2

mergeNodePreserveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected