/[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 14 by dpavlin, Sat Aug 28 15:19:22 2004 UTC revision 15 by dpavlin, Sun Sep 5 17:57:21 2004 UTC
# Line 5  use strict; Line 5  use strict;
5  use warnings;  use warnings;
6  use HTML::Entities;  use HTML::Entities;
7    
8  our $VERSION = '0.03';  our $VERSION = '0.04';
9    
10  use Exporter 'import';  use Exporter 'import';
11  use Carp;  use Carp;
# Line 407  use strict; Line 407  use strict;
407  use Carp;  use Carp;
408  use File::Path;  use File::Path;
409  use Text::Iconv;  use Text::Iconv;
410    use POSIX;
411    
412  use base 'jsFind';  use base 'jsFind';
413    
# Line 776  sub to_xml { Line 777  sub to_xml {
777          return $d;          return $d;
778  }  }
779    
780    =head2 base62
781    
782    Convert number to base62 (used for jsFind index filenames).
783    
784     my $n = $tree->base62(50);
785    
786    =cut
787    
788    sub base62 {
789            my $self = shift;
790    
791            my $value = shift;
792    
793            confess("need non-negative number") if (! defined($value) || $value < 0);
794    
795            my @digits = qw(
796                    0 1 2 3 4 5 6 7 8 9
797                    a b c d e f g h i j k l m n o p q r s t u v w x y z
798                    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
799            );
800    
801            my $base = scalar(@digits);
802            my $out = "";
803            my $pow = 1;
804            my $pos = 0;
805    
806    
807            if($value == 0) {
808                    return "0";
809            }
810    
811            while($value > 0) {
812                    $pos = $value % $base;
813                    $out = $digits[$pos] . $out;
814                    $value = floor($value/$base);
815                    $pow *= $base;
816            }
817    
818            return $out;
819    }
820    
821  =head2 to_jsfind  =head2 to_jsfind
822    
823  Create jsFind xml files  Create jsFind xml files
# Line 786  Returns number of elements created Line 828  Returns number of elements created
828    
829  =cut  =cut
830    
   
831  sub to_jsfind {  sub to_jsfind {
832          my $self = shift;          my $self = shift;
833          my ($path,$file) = @_;          my ($path,$file) = @_;
# Line 796  sub to_jsfind { Line 837  sub to_jsfind {
837          confess("path is undefined.") unless ($path);          confess("path is undefined.") unless ($path);
838          confess("file is undefined. Did you call \$t->root->to_jsfind(..) instead of \$t->to_jsfind(..) ?") unless (defined($file));          confess("file is undefined. Did you call \$t->root->to_jsfind(..) instead of \$t->to_jsfind(..) ?") unless (defined($file));
839    
840            $file = $self->base62($file);
841    
842          my $nr_keys = 0;          my $nr_keys = 0;
843    
844          my ($k, $d, $s) = @$self;          my ($k, $d, $s) = @$self;

Legend:
Removed from v.14  
changed lines
  Added in v.15

  ViewVC Help
Powered by ViewVC 1.1.26