s/</</g;
s/>/>/g;
s/\n/<br>\n/g;
- s/\t/ /eg;
+ s/\t/ /g;
s/ / /g;
};
if ($@){ return defined wantarray ? @_ : undef }
}
sub AutoURL($){
+ # This sub assumes your string does not match /(["<>])\cC\1/
my $ref;
if (defined wantarray){
$ref = \(my $copy = $_[0]);
$ref = \$_[0];
}
eval {
- my ($p, $b, $c);
- $$ref =~ s/"/"\cC"/g;
- $$ref =~ s/>/>\cC>/g;
+ $$ref =~ s/"/"\cC"/g; # Single characters are easier to match :)
+ $$ref =~ s/>/>\cC>/g; # so we can just use a character class []
$$ref =~ s/</<\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+;)/&/g, s/\"/"/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+;)/&/g;
+ s/\"/"/g;
+ my $href = ($scheme =~ /www\./i ? "http://$_" : $_);
+ qq{<a href="$href" target="_blank">$_</a>$trailing};
}eg;
-
$$ref =~ s/"\cC"/"/g;
$$ref =~ s/>\cC>/>/g;
$$ref =~ s/<\cC</</g;