--- trunk/jsFind.pm 2004/07/21 15:44:15 8 +++ trunk/jsFind.pm 2004/07/21 23:37:49 9 @@ -4,7 +4,7 @@ use strict; use warnings; -our $VERSION = '0.01'; +our $VERSION = '0.02'; =head1 NAME @@ -305,13 +305,25 @@ 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): + + $root->to_jsfind('/full/path/to/index/dir/','ISO-8859-2','UTF-8'); + =cut +my $iconv; + sub to_jsfind { my $self = shift; my $path = shift || confess "to_jsfind need path to your index!"; + my ($from_cp,$to_cp) = @_; + if ($from_cp && $to_cp) { + $iconv = Text::Iconv->new($from_cp,$to_cp); + } + $path .= "/" if ($path =~ /\/$/); carp "create directory for index '$path': $!" if (! -w $path); @@ -324,6 +336,23 @@ $_[0] cmp $_[1]; } +=head3 _recode + +This is internal function to recode charset. + +=cut + +sub _recode { + my $self = shift; + my $text = shift || return; + + if ($iconv) { + return $iconv->convert($text) || $text; + } else { + return $text; + } +} + ##################################################################### =head2 jsFind::Node methods @@ -348,6 +377,9 @@ use Carp; use File::Path; +use Text::Iconv; + +use base 'jsFind'; my $KEYS = 0; my $DATA = 1; @@ -745,8 +777,8 @@ open(K, "> ${path}/${file}.xml") || croak "can't open '$path/$file.xml': $!"; open(D, "> ${path}/_${file}.xml") || croak "can't open '$path/_$file.xml': $!"; - print K $key_xml; - print D $data_xml; + print K $self->SUPER::_recode($key_xml); + print D $self->SUPER::_recode($data_xml); close(K); close(D);