--- trunk/jsFind.pm 2004/10/10 05:11:29 34 +++ trunk/jsFind.pm 2004/10/24 11:13:22 35 @@ -5,7 +5,7 @@ use warnings; use HTML::Entities; -our $VERSION = '0.05'; +our $VERSION = '0.06'; use Exporter 'import'; use Carp; @@ -358,18 +358,55 @@ Create xml index files for jsFind. This should be called after your B-Tree has been filled with data. - $root->to_jsfind('/full/path/to/index/dir/'); + $root->to_jsfind( + dir => '/full/path/to/index/dir/', + data_codepage => 'ISO-8859-2', + index_codepage => 'UTF-8', + output_filter => sub { + my $t = shift || return; + $t =~ s/è/e/; + } + ); + +All options except C are optional. Returns number of nodes in created tree. -There is also longer version if you want to recode your data charset -into different one (probably UTF-8): +Options: + +=over 4 + +=item dir + +Full path to directory for index (which will be created if needed). + +=item data_codepage + +If your imput data isn't in C encoding, you will have to specify +this option. - $root->to_jsfind('/full/path/to/index/dir/','ISO-8859-2','UTF-8'); +=item index_codepage -Destination encoding is UTF-8 by default, so you don't have to specify it. +If your index encoding is not C use this option. - $root->to_jsfind('/full/path/to/index/dir/','WINDOWS-1250'); +If you are not using supplied JavaScript search code, or your browser is +terribly broken and thinks that index shouldn't be in UTF-8 encoding, use +this option to specify encoding for created XML index. + +=item output_filter + +B + +Code ref to sub which can do modifications on resulting XML file for node. +Encoding of this data will be in L and you have to take care +not to break XML structure. Calling L on your result index +(like C does in this distribution) is a good idea after using +this option. + +This option is also right place to plug in unaccenting function using +L. + +=back =cut @@ -379,21 +416,22 @@ sub to_jsfind { my $self = shift; - my $path = shift || confess "to_jsfind need path to your index!"; + my %arg = @_; - my ($from_cp,$to_cp) = @_; + confess "to_jsfind need path to your index directory !" unless ($arg{'dir'}); - $to_cp ||= 'UTF-8'; + my $data_codepage = $arg{'data_codepage'}; + my $index_codepage = $arg{'index_codepage'} || 'UTF-8'; - if ($from_cp && $to_cp) { - $iconv = Text::Iconv->new($from_cp,$to_cp); - } - $iconv_l1 = Text::Iconv->new('ISO-8859-1',$to_cp); + # create ISO-8859-1 iconv for HTML::Entities decode + $iconv_l1 = Text::Iconv->new('ISO-8859-1',$index_codepage); - $path .= "/" if ($path =~ /\/$/); - #carp "creating directory for index '$path'" if (! -w $path); + # create another iconv for data + if ($data_codepage && $index_codepage) { + $iconv = Text::Iconv->new($data_codepage,$index_codepage); + } - return $self->root->to_jsfind($path,"0"); + return $self->root->to_jsfind($arg{'dir'},"0"); }