MCPcopy Create free account
hub / github.com/JordanCoin/codemap / extractImportPath

Function extractImportPath

scanner/astgrep.go:341–428  ·  view source on GitHub ↗
(text string)

Source from the content-addressed store, hash-verified

339}
340
341func extractImportPath(text string) string {
342 // Handle various import formats
343 text = strings.TrimSpace(text)
344
345 // C/C++: #include <header> or #include "header"
346 if strings.HasPrefix(text, "#include") {
347 // Try angle brackets first
348 if start := strings.Index(text, "<"); start >= 0 {
349 if end := strings.Index(text[start:], ">"); end > 0 {
350 return text[start+1 : start+end]
351 }
352 }
353 }
354
355 // Bash: source ./file or . ./file
356 if strings.HasPrefix(text, "source ") || strings.HasPrefix(text, ". ") {
357 parts := strings.Fields(text)
358 if len(parts) >= 2 {
359 return parts[1]
360 }
361 }
362
363 // Find quoted strings (Go, TS/JS, Python, C/C++ with quotes)
364 for _, q := range []string{`"`, `'`, "`"} {
365 if idx := strings.Index(text, q); idx >= 0 {
366 end := strings.Index(text[idx+1:], q)
367 if end > 0 {
368 return text[idx+1 : idx+1+end]
369 }
370 }
371 }
372
373 // C#: using Foo.Bar.Baz; / using static Foo.Bar; / using Alias = Foo.Bar.Baz;
374 if strings.HasPrefix(text, "using ") {
375 text = strings.TrimPrefix(text, "using ")
376 text = strings.TrimSuffix(text, ";")
377 text = strings.TrimSpace(text)
378
379 text = strings.TrimPrefix(text, "static ")
380
381 if idx := strings.Index(text, "="); idx >= 0 {
382 text = text[idx+1:]
383 }
384
385 return strings.TrimSpace(text)
386 }
387
388 // Python: import foo
389 if strings.HasPrefix(text, "import ") {
390 parts := strings.Fields(text)
391 if len(parts) >= 2 {
392 return parts[1]
393 }
394 }
395
396 // Python: from foo import bar
397 if strings.HasPrefix(text, "from ") {
398 parts := strings.Fields(text)

Callers 1

ScanDirectoryMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected