|
| 1 | +module Docs |
| 2 | + class Cpp |
| 3 | + class EntriesFilter < Docs::EntriesFilter |
| 4 | + REPLACE_NAMES = { |
| 5 | + 'Error directive' => '#error directive', |
| 6 | + 'Filename and line information' => '#line directive', |
| 7 | + 'Implementation defined behavior control' => '#pragma directive', |
| 8 | + 'Replacing text macros' => '#define directive', |
| 9 | + 'Source file inclusion' => '#include directive' } |
| 10 | + |
| 11 | + def get_name |
| 12 | + name = at_css('#firstHeading').content.strip |
| 13 | + name.sub! 'C++ concepts: ', '' |
| 14 | + name.sub! 'C++ keywords: ', '' |
| 15 | + name.sub! 'C++ ', '' |
| 16 | + name.sub! %r{\s\(.+\)}, '' |
| 17 | + name.sub! %r{\AStandard library header <(.+)>\z}, '\1' |
| 18 | + name = name.split(',').first |
| 19 | + REPLACE_NAMES[name] || name |
| 20 | + end |
| 21 | + |
| 22 | + def get_type |
| 23 | + if at_css('#firstHeading').content.include?('C++ keyword') |
| 24 | + 'Keywords' |
| 25 | + elsif type = at_css('.t-navbar > div:nth-child(4) > :first-child').try(:content) |
| 26 | + type.strip! |
| 27 | + type.sub! ' library', '' |
| 28 | + type.sub! ' utilities', '' |
| 29 | + type.sub! 'C++ ', '' |
| 30 | + type.capitalize! |
| 31 | + type |
| 32 | + end |
| 33 | + end |
| 34 | + |
| 35 | + def additional_entries |
| 36 | + return [] unless include_default_entry? |
| 37 | + names = at_css('#firstHeading').content.gsub(%r{\(.+?\)}, '').split(',')[1..-1] |
| 38 | + names.each(&:strip!).reject! do |name| |
| 39 | + name.size <= 2 || name == '...' || name =~ /\A[<>]/ || name.start_with?('operator') |
| 40 | + end |
| 41 | + names.map { |name| [name] } |
| 42 | + end |
| 43 | + |
| 44 | + def include_default_entry? |
| 45 | + return @include_default_entry if defined? @include_default_entry |
| 46 | + @include_default_entry = at_css('.t-navbar > div:nth-child(4) > a') && at_css('#firstHeading').content !~ /\A\s*operator./ |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | +end |
0 commit comments