| 76 | } |
| 77 | |
| 78 | func (sa *SourceAnalyzer) extractInternalFunctions(content string) []string { |
| 79 | lines := strings.Split(content, "\n") |
| 80 | var ( |
| 81 | functions []string |
| 82 | currentFunc strings.Builder |
| 83 | inFunction, hasPHPFunc bool |
| 84 | braceCount int |
| 85 | ) |
| 86 | |
| 87 | for i, line := range lines { |
| 88 | trimmedLine := strings.TrimSpace(line) |
| 89 | |
| 90 | if strings.HasPrefix(trimmedLine, "func ") && !inFunction { |
| 91 | inFunction = true |
| 92 | braceCount = 0 |
| 93 | hasPHPFunc = false |
| 94 | currentFunc.Reset() |
| 95 | |
| 96 | // look backwards for export_php comment |
| 97 | for j := i - 1; j >= 0 && j >= i-5; j-- { |
| 98 | prevLine := strings.TrimSpace(lines[j]) |
| 99 | if prevLine == "" { |
| 100 | continue |
| 101 | } |
| 102 | |
| 103 | if strings.Contains(prevLine, "export_php:") { |
| 104 | hasPHPFunc = true |
| 105 | |
| 106 | break |
| 107 | } |
| 108 | |
| 109 | if !strings.HasPrefix(prevLine, "//") { |
| 110 | break |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if inFunction { |
| 116 | currentFunc.WriteString(line + "\n") |
| 117 | |
| 118 | for _, char := range line { |
| 119 | switch char { |
| 120 | case '{': |
| 121 | braceCount++ |
| 122 | case '}': |
| 123 | braceCount-- |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | if braceCount == 0 && strings.Contains(line, "}") { |
| 128 | funcContent := currentFunc.String() |
| 129 | |
| 130 | if !hasPHPFunc { |
| 131 | functions = append(functions, strings.TrimSpace(funcContent)) |
| 132 | } |
| 133 | |
| 134 | inFunction = false |
| 135 | currentFunc.Reset() |