v2.22 release
[perl/plp/.git] / plpfunc.pm
index 49bb63cd8922b5bb44ea7013059b304ee75e4e27..a113c76615a303a0d7c6a89db19eb791c8d0d033 100644 (file)
@@ -31,7 +31,7 @@ sub Entity(@){
            s/</&lt;/g;
            s/>/&gt;/g;
            s/\n/<br>\n/g;
-           s/\t/    /eg;
+           s/\t/&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;/g;
            s/  /&nbsp;&nbsp;/g;
        };
        if ($@){ return defined wantarray ? @_ : undef }
@@ -108,6 +108,7 @@ sub Counter($){
 }
 
 sub AutoURL($){
+    # This sub assumes your string does not match /(["<>])\cC\1/
     my $ref;    
     if (defined wantarray){
        $ref = \(my $copy = $_[0]);
@@ -115,19 +116,21 @@ sub AutoURL($){
        $ref = \$_[0];
     }
     eval {
-       my ($p, $b, $c);
-       $$ref =~ s/&quot;/"\cC"/g;
-       $$ref =~ s/&gt;/>\cC>/g;
+       $$ref =~ s/&quot;/"\cC"/g; # Single characters are easier to match :)
+       $$ref =~ s/&gt;/>\cC>/g;   # so we can just use a character class []
        $$ref =~ s/&lt;/<\cC</g;
+       
        # Now this is a big, ugly regex! But hey - it works :)    
        $$ref =~ s{((\w+://|www\.|WWW\.)[a-zA-Z0-9\.\@:-]+[^\"\'>< \r\t\n]*)}{
-           local $_ = $1, $p = $2, ((($b) = /([\.,!\?\(\)\[\]]+$)/) ? s/// :
-           undef), s/&(?!\x23?\w+;)/&amp;/g, s/\"/&quot;/g, $c = 
-           ($p eq 'www.' || $p eq 'WWW.' ? "http://$_" : $_),
-           qq{<a href="$c" target="_blank">$_</a>$b}
+           local $_ = $1;
+           my $scheme = $2;
+           s/// if (my $trailing) = /([\.,!\?\(\)\[\]]+$)/;
+           s/&(?!\x23?\w+;)/&amp;/g;
+           s/\"/&quot;/g;
+           my $href = ($scheme =~ /www\./i ? "http://$_" : $_);
+           qq{<a href="$href" target="_blank">$_</a>$trailing};
        }eg;
 
-
        $$ref =~ s/"\cC"/&quot;/g;
        $$ref =~ s/>\cC>/&gt;/g;
        $$ref =~ s/<\cC</&lt;/g;