* After the `namespace` keyword ending at `from`: the name as written and the * offset of the `{` that opens the body. Null for anything else, such as * `using namespace std;` or `namespace fs = std::filesystem;`. Takes C++17 * attributes (`namespace [[deprecated]] old {`), nested and inline name
(source: string, from: number)
| 170 | * (`namespace std _GLIBCXX_VISIBILITY(default) {`). |
| 171 | */ |
| 172 | function namespaceHead(source: string, from: number): { name: string; brace: number } | null { |
| 173 | let i = skipBlank(source, from); |
| 174 | while (source.startsWith('[[', i)) { |
| 175 | const end = source.indexOf(']]', i + 2); |
| 176 | if (end < 0) return null; |
| 177 | i = skipBlank(source, end + 2); |
| 178 | } |
| 179 | let nameStart = -1; |
| 180 | let nameEnd = -1; |
| 181 | for (let end = wordEnd(source, i); end >= 0; end = wordEnd(source, i)) { |
| 182 | if (nameStart < 0) nameStart = i; |
| 183 | nameEnd = end; |
| 184 | i = skipBlank(source, end); |
| 185 | if (!source.startsWith('::', i)) break; |
| 186 | i = skipBlank(source, i + 2); |
| 187 | const inline = wordEnd(source, i); |
| 188 | if (inline >= 0 && source.slice(i, inline) === 'inline') i = skipBlank(source, inline); |
| 189 | } |
| 190 | for (let end = wordEnd(source, i); end >= 0 && nameStart >= 0; end = wordEnd(source, i)) { |
| 191 | const paren = skipBlank(source, end); |
| 192 | const after = source.charCodeAt(paren) === 40 ? parenGroupEnd(source, paren) : -1; |
| 193 | if (after < 0) return null; |
| 194 | i = skipBlank(source, after); |
| 195 | } |
| 196 | if (source.charCodeAt(i) !== 123) return null; |
| 197 | return { name: nameStart < 0 ? '' : source.slice(nameStart, nameEnd), brace: i }; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Scan `source` (a C++ file as the parser saw it, after preParse) for its |
no test coverage detected