extract aliases like std::string, template specializations like std::atomic_bool and helper functions like std::is_same_v
(self, text)
| 380 | return names |
| 381 | |
| 382 | def _extract_keywords(self, text): |
| 383 | """ |
| 384 | extract aliases like std::string, template specializations like std::atomic_bool |
| 385 | and helper functions like std::is_same_v |
| 386 | """ |
| 387 | soup = BeautifulSoup(text, "lxml") |
| 388 | names = [] |
| 389 | |
| 390 | # search for typedef list |
| 391 | for x in soup.find_all('table'): |
| 392 | # just searching for "Type" is not enough, see std::is_same |
| 393 | p = x.find_previous_sibling('h3') |
| 394 | if p: |
| 395 | if p.get_text().strip() == "Member types": |
| 396 | continue |
| 397 | |
| 398 | typedefTable = False |
| 399 | for tr in x.find_all('tr'): |
| 400 | tds = tr.find_all('td') |
| 401 | if len(tds) == 2: |
| 402 | if re.match(r"\s*Type\s*", tds[0].get_text()): |
| 403 | typedefTable = True |
| 404 | elif typedefTable: |
| 405 | res = re.search(r'^\s*(\S*)\s+.*$', tds[0].get_text()) |
| 406 | if res and res.group(1): |
| 407 | names.append(res.group(1)) |
| 408 | elif not typedefTable: |
| 409 | break |
| 410 | if typedefTable: |
| 411 | break |
| 412 | |
| 413 | # search for "Helper variable template" list |
| 414 | for x in soup.find_all('h3'): |
| 415 | variableTemplateHeader = False |
| 416 | if x.find('span', id="Helper_variable_template"): |
| 417 | e = x.find_next_sibling() |
| 418 | while e.name == "": |
| 419 | e = e.find_next_sibling() |
| 420 | if e.name == "table": |
| 421 | for tr in e.find_all('tr'): |
| 422 | text = re.sub('\n', ' ', tr.get_text()) |
| 423 | res = re.search(r'^.* (\S+)\s*=.*$', text) |
| 424 | if res: |
| 425 | names.append(res.group(1)) |
| 426 | # search for "Helper types" list |
| 427 | for x in soup.find_all('h3'): |
| 428 | variableTemplateHeader = False |
| 429 | if x.find('span', id="Helper_types"): |
| 430 | e = x.find_next_sibling() |
| 431 | while e.name == "": |
| 432 | e = e.find_next_sibling() |
| 433 | if e.name == "table": |
| 434 | for tr in e.find_all('tr'): |
| 435 | text = re.sub('\n', ' ', tr.get_text()) |
| 436 | res = re.search(r'^.* (\S+)\s*=.*$', text) |
| 437 | if res: |
| 438 | names.append(res.group(1)) |
| 439 | return [html.unescape(n) for n in names] |