--- trunk/lib/WAIT/Filter.pm 2005/07/15 18:58:37 117 +++ trunk/lib/WAIT/Filter.pm 2005/07/15 18:59:10 118 @@ -16,9 +16,12 @@ require WAIT; use strict; use Carp; -use vars qw($VERSION @ISA @EXPORT_OK %STOP $SPLIT $AUTOLOAD); +use vars qw($VERSION @ISA @EXPORT_OK %STOP $SPLIT $UNAC $ICONV $AUTOLOAD); use subs qw(grundform); +use Text::Unaccent; +use Text::Iconv; + require Exporter; @ISA = qw(Exporter); @@ -47,6 +50,23 @@ } ]; +$UNAC = q[ + sub unac_CHARSET { + map split(' ',unac_string('CHARSET', $_) || $_), @_; + } +]; + +my $iconv; + +$ICONV = q[ + sub iconv_CHARSETfrom_CHARSETto { + my $ic = $iconv->{'CHARSETfrom_CHARSETto'}); + $ic ||= $iconv->{'CHARSETfrom_CHARSETto'} = Text::Iconv->new('CHARSETfrom','CHARSETto'); + map split(' ',$ic->convert($_) || $_), @_; + } +]; + + sub AUTOLOAD { my $func = $AUTOLOAD; $func =~ s/.*:://; @@ -73,7 +93,7 @@ goto \&date; } elsif ($func eq 'decode_entities') { eval {require HTML::Entities;}; - croak "You must have HTML::Entities to use 'date'" + croak "You must have HTML::Entities to use 'decode_entities'" if $@ ne ''; *decode_entities = HTML::Entities->can('decode_entities'); goto &decode_entities; @@ -87,6 +107,26 @@ $s; }; goto \&$func; + } elsif ($func =~ /unac_(.+)/) { + my $charset = $1; + my $unac = $UNAC; + $unac =~ s/CHARSET/$charset/g; +print "### $unac ###\n"; + eval $unac; + if ($@ eq '') { + goto &$func; + } + } elsif ($func =~ /iconv_([^_]+)_([^_]+)/) { + my ($cf,$ct) = ($1,$2); + my $iconv = $ICONV; +print "### $cf -> $ct\n"; + $iconv =~ s/CHARSETfrom/$cf/gs; + $iconv =~ s/CHARSETto/$ct/gs; +print "### $iconv ###\n"; + eval $iconv; + if ($@ eq '') { + goto &$func; + } } Carp::confess "Class WAIT::Filter::$func not found"; }