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

Function findIncludesInContent

pkg/cli/remove_command.go:398–422  ·  view source on GitHub ↗

findIncludesInContent finds all import references in content

(content string)

Source from the content-addressed store, hash-verified

396
397// findIncludesInContent finds all import references in content
398func 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.

Calls 1

parseIncludePathFunction · 0.85