MCPcopy Create free account
hub / github.com/github/gh-aw / extractNestedSubYAML

Function extractNestedSubYAML

pkg/parser/json_path_locator.go:326–352  ·  view source on GitHub ↗
(yamlContent string, nestedSection NestedSection)

Source from the content-addressed store, hash-verified

324}
325
326func extractNestedSubYAML(yamlContent string, nestedSection NestedSection) (string, int) {
327 lines := strings.Split(yamlContent, "\n")
328 subYAMLLines := make([]string, 0, nestedSection.endLine-nestedSection.startLine+1)
329 var baseIndent = -1
330 for lineNum := nestedSection.startLine; lineNum <= nestedSection.endLine && lineNum < len(lines); lineNum++ {
331 line := lines[lineNum]
332
333 if lineNum == nestedSection.startLine {
334 continue
335 }
336
337 lineIndent := len(line) - len(strings.TrimLeft(line, " \t"))
338 if baseIndent == -1 && strings.TrimSpace(line) != "" {
339 baseIndent = lineIndent
340 }
341
342 var normalizedLine string
343 if lineIndent >= baseIndent && baseIndent > 0 {
344 normalizedLine = line[baseIndent:]
345 } else {
346 normalizedLine = line
347 }
348
349 subYAMLLines = append(subYAMLLines, normalizedLine)
350 }
351 return strings.Join(subYAMLLines, "\n"), baseIndent
352}
353
354func mapNestedLocationToOriginal(subLocation JSONPathLocation, nestedSection NestedSection, baseIndent int) JSONPathLocation {
355 originalLine := nestedSection.startLine + subLocation.Line // +1 to skip section header, -1 for 0-based indexing

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected