/[jsFind]/trunk/jsFind.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/jsFind.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by dpavlin, Wed Jul 21 15:44:15 2004 UTC revision 9 by dpavlin, Wed Jul 21 23:37:49 2004 UTC
# Line 4  use 5.008004; Line 4  use 5.008004;
4  use strict;  use strict;
5  use warnings;  use warnings;
6    
7  our $VERSION = '0.01';  our $VERSION = '0.02';
8    
9  =head1 NAME  =head1 NAME
10    
# Line 305  your B-Tree has been filled with data. Line 305  your B-Tree has been filled with data.
305    
306  Returns number of nodes in created tree.  Returns number of nodes in created tree.
307    
308    There is also longer version if you want to recode your data charset
309    into different one (probably UTF-8):
310    
311     $root->to_jsfind('/full/path/to/index/dir/','ISO-8859-2','UTF-8');
312    
313  =cut  =cut
314    
315    my $iconv;
316    
317  sub to_jsfind {  sub to_jsfind {
318          my $self = shift;          my $self = shift;
319    
320          my $path = shift || confess "to_jsfind need path to your index!";          my $path = shift || confess "to_jsfind need path to your index!";
321    
322            my ($from_cp,$to_cp) = @_;
323            if ($from_cp && $to_cp) {
324                    $iconv = Text::Iconv->new($from_cp,$to_cp);
325            }
326    
327          $path .= "/" if ($path =~ /\/$/);          $path .= "/" if ($path =~ /\/$/);
328          carp "create directory for index '$path': $!" if (! -w $path);          carp "create directory for index '$path': $!" if (! -w $path);
329    
# Line 324  sub default_cmp { Line 336  sub default_cmp {
336    $_[0] cmp $_[1];    $_[0] cmp $_[1];
337  }  }
338    
339    =head3 _recode
340    
341    This is internal function to recode charset.
342    
343    =cut
344    
345    sub _recode {
346            my $self = shift;
347            my $text = shift || return;
348    
349            if ($iconv) {
350                    return $iconv->convert($text) || $text;
351            } else {
352                    return $text;
353            }
354    }
355    
356  #####################################################################  #####################################################################
357    
358  =head2 jsFind::Node methods  =head2 jsFind::Node methods
# Line 348  use strict; Line 377  use strict;
377    
378  use Carp;  use Carp;
379  use File::Path;  use File::Path;
380    use Text::Iconv;
381    
382    use base 'jsFind';
383    
384  my $KEYS = 0;  my $KEYS = 0;
385  my $DATA = 1;  my $DATA = 1;
# Line 745  sub to_jsfind { Line 777  sub to_jsfind {
777          open(K, "> ${path}/${file}.xml") || croak "can't open '$path/$file.xml': $!";          open(K, "> ${path}/${file}.xml") || croak "can't open '$path/$file.xml': $!";
778          open(D, "> ${path}/_${file}.xml") || croak "can't open '$path/_$file.xml': $!";          open(D, "> ${path}/_${file}.xml") || croak "can't open '$path/_$file.xml': $!";
779    
780          print K $key_xml;          print K $self->SUPER::_recode($key_xml);
781          print D $data_xml;          print D $self->SUPER::_recode($data_xml);
782    
783          close(K);          close(K);
784          close(D);          close(D);

Legend:
Removed from v.8  
changed lines
  Added in v.9

  ViewVC Help
Powered by ViewVC 1.1.26