Changeset 11984


Ignore:
Timestamp:
07/24/10 20:18:06 (19 months ago)
Author:
azawawi
Message:

More method refactoring for readability

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/parse_wxwidgets_docs.pl

    r11983 r11984  
    106106 
    107107# 
     108# Process wxClassName HTML file 
     109#  
     110sub process_class { 
     111    my ($class, $file) = @_; 
     112     
     113    my $oldclass; 
     114    my $pod_text = ''; 
     115    if(open my $html_file, '<', $file) { 
     116        my $desc = ''; 
     117        my $name; 
     118        while(my $line = <$html_file>) { 
     119            if($line =~ /<H3>(.+?)<\/H3>/) { 
     120                $name = $1; 
     121                $name =~ s/wx(.+?)/Wx::$1/; 
     122                if($name =~ /^Wx::(.+?)::(.+?)$/) { 
     123                    my $method = $2; 
     124                    if($method eq "wx$1") { 
     125                        # Convert C++ constructor to ::new 
     126                        $name = $class . '::new'; 
     127                    } elsif($method =~ /^~.+/) { 
     128                        # Convert C++ destructor to ::DESTROY 
     129                        $name = $class . '::DESTROY'; 
     130                    } elsif ($method =~ /^operator.+/) { 
     131                        # Ignore operators 
     132                        $name = undef; 
     133                    } 
     134                } 
     135                $desc = ''; 
     136            } elsif($line =~ /^\s*$/) { 
     137                if($name) { 
     138                    if(!$oldclass || $class ne $oldclass) { 
     139                        # print out new class header 
     140                        $pod_text .= "=head1 $class\n\n"; 
     141                        $oldclass = $class; 
     142                    } 
     143 
     144                    # print out method description 
     145                    $desc = HTML::FormatText->new->format(parse_html($desc)); 
     146                    $pod_text .= "=head2 $name\n$desc\n"; 
     147 
     148                    $name = undef; 
     149                } 
     150            } else { 
     151                $desc .= $line; 
     152            } 
     153        } 
     154        close $html_file; 
     155    } 
     156     
     157    return $pod_text; 
     158} 
     159 
     160# 
    108161# Writes wxwidgets.pod... :) 
    109162# 
     
    118171            my $class = $wxclass->{class}; 
    119172            print "Processing $class...\n"; 
    120              
    121             if(open my $html_file, '<', $file) { 
    122                 my $desc = ''; 
    123                 my $name; 
    124                 while(my $line = <$html_file>) { 
    125                     if($line =~ /<H3>(.+?)<\/H3>/) { 
    126                         $name = $1; 
    127                         $name =~ s/wx(.+?)/Wx::$1/; 
    128                         if($name =~ /^Wx::(.+?)::(.+?)$/) { 
    129                             my $method = $2; 
    130                             if($method eq "wx$1") { 
    131                                 # Convert C++ constructor to ::new 
    132                                 $name = $class . '::new'; 
    133                             } elsif($method =~ /^~.+/) { 
    134                                 # Convert C++ destructor to ::DESTROY 
    135                                 $name = $class . '::DESTROY'; 
    136                             } elsif ($method =~ /^operator.+/) { 
    137                                 # Ignore operators 
    138                                 $name = undef; 
    139                             } 
    140                         } 
    141                         $desc = ''; 
    142                     } elsif($line =~ /^\s*$/) { 
    143                         if($name) { 
    144                             if(!$oldclass || $class ne $oldclass) { 
    145                                 # print out new class header 
    146                                 print $pod "=head1 $class\n\n"; 
    147                                 $oldclass = $class; 
    148                             } 
    149  
    150                             # print out method description 
    151                             $desc = HTML::FormatText->new->format(parse_html($desc)); 
    152                             print $pod "=head2 $name\n$desc\n"; 
    153  
    154                             $name = undef; 
    155                         } 
    156                     } else { 
    157                         $desc .= $line; 
    158                     } 
    159                 } 
    160                 close $html_file; 
    161             } 
     173            print $pod process_class($class, $file); 
    162174        } 
    163175        close $pod; 
Note: See TracChangeset for help on using the changeset viewer.