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

Function findNestedSectionStart

pkg/parser/json_path_locator.go:388–409  ·  view source on GitHub ↗
(lines []string, pathSegments []PathSegment)

Source from the content-addressed store, hash-verified

386}
387
388func findNestedSectionStart(lines []string, pathSegments []PathSegment) (int, int) {
389 currentLevel := 0
390 for lineNum, line := range lines {
391 trimmedLine := strings.TrimSpace(line)
392 if trimmedLine == "" || strings.HasPrefix(trimmedLine, "#") {
393 continue
394 }
395 lineLevel := (len(line) - len(strings.TrimLeft(line, " \t"))) / 2
396 if currentLevel >= len(pathSegments) {
397 continue
398 }
399 segment := pathSegments[currentLevel]
400 if segment.Type != "key" || !matchesPathSegmentKey(trimmedLine, segment.Value) || lineLevel != currentLevel {
401 continue
402 }
403 if currentLevel == len(pathSegments)-1 {
404 return lineNum, lineLevel + 1
405 }
406 currentLevel++
407 }
408 return -1, 0
409}
410
411func matchesPathSegmentKey(trimmedLine, key string) bool {
412 keyPattern := regexp.MustCompile(`^` + regexp.QuoteMeta(key) + `\s*:`)

Callers 1

findNestedSectionFunction · 0.85

Calls 1

matchesPathSegmentKeyFunction · 0.85

Tested by

no test coverage detected