(lines []string, pathSegments []PathSegment)
| 386 | } |
| 387 | |
| 388 | func 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 | |
| 411 | func matchesPathSegmentKey(trimmedLine, key string) bool { |
| 412 | keyPattern := regexp.MustCompile(`^` + regexp.QuoteMeta(key) + `\s*:`) |
no test coverage detected