findIncludesInContent finds all import references in content
(content string)
| 396 | |
| 397 | // findIncludesInContent finds all import references in content |
| 398 | func findIncludesInContent(content string) ([]string, error) { |
| 399 | var includes []string |
| 400 | // Manual index-based scan avoids the iter.Seq yield overhead of strings.Lines. |
| 401 | for remaining := content; remaining != ""; { |
| 402 | var line string |
| 403 | if idx := strings.IndexByte(remaining, '\n'); idx >= 0 { |
| 404 | line = remaining[:idx] |
| 405 | remaining = remaining[idx+1:] |
| 406 | } else { |
| 407 | line = remaining |
| 408 | remaining = "" |
| 409 | } |
| 410 | if path := parseIncludePath(line); path != "" { |
| 411 | if includes == nil { |
| 412 | includes = make([]string, 0, 4) |
| 413 | } |
| 414 | includes = append(includes, path) |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | if includes == nil { |
| 419 | return []string{}, nil |
| 420 | } |
| 421 | return includes, nil |
| 422 | } |
| 423 | |
| 424 | // parseIncludePath extracts the file path from @include/@import/{{#import}} directive lines |
| 425 | // without allocating a regex submatch slice or a directive struct. |