* What a parameter list holds at its top level — outside nested parentheses * and brackets, so an array bound (`int a[N & M]`), an attribute or a function * pointer's own parameters drop out. `open` is the list's `(`. Null when the * list doesn't close within a few thousand characters or runs int
(code: string, open: number)
| 889 | * with no string built. |
| 890 | */ |
| 891 | function topLevelParameters(code: string, open: number): string | null { |
| 892 | let depth = 0; |
| 893 | let nested = false; |
| 894 | let close = -1; |
| 895 | const end = Math.min(code.length, open + 4000); |
| 896 | for (let i = open + 1; i < end && close < 0; i++) { |
| 897 | const ch = code.charCodeAt(i); |
| 898 | if (ch === 0x3b /* ; */ || ch === 0x7b /* { */ || ch === 0x7d /* } */) return null; |
| 899 | if (ch === 0x28 /* ( */ || ch === 0x5b /* [ */) { |
| 900 | depth++; |
| 901 | nested = true; |
| 902 | } else if (ch === 0x29 /* ) */ || ch === 0x5d /* ] */) { |
| 903 | if (depth === 0) { |
| 904 | if (ch !== 0x29) return null; |
| 905 | close = i; |
| 906 | } else depth--; |
| 907 | } |
| 908 | } |
| 909 | if (close < 0) return null; |
| 910 | let params = code.slice(open + 1, close); |
| 911 | if (!/[&=<]/.test(params)) return null; |
| 912 | // Innermost groups first, until none is left. |
| 913 | while (nested && /[([]/.test(params)) { |
| 914 | const flat = params.replace(/\([^()[\]]*\)|\[[^()[\]]*\]/g, ' '); |
| 915 | if (flat === params) return null; |
| 916 | params = flat; |
| 917 | } |
| 918 | return params; |
| 919 | } |
| 920 | |
| 921 | /** |
| 922 | * A reference declarator after its type, spaced the way references are and |
no outgoing calls
no test coverage detected