usr bin perl use strict use Benchmark our msg Lorem ipsum dolor sit am

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/perl
use strict;
use Benchmark;
our $msg="Lorem *ipsum* dolor *sit amet*, consectetur adipisicing elit, sed do eiusmod /tempor incididunt ut/ labore et dolore magna aliqua.\nhttp://juick.com/ugnich/?tag=juick&page=2 - Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat: #12345/67.\nDuis aute irure dolor in reprehenderit in #12345 #1234 voluptate velit esse \@cillum\@dolore.eu fugiat nulla \@pariatur.\nExcepteur sint occaecat cupidatat non proident (http://juick.com/last?tag=juick&page=2), sunt in culpa qui officia deserunt mollit anim id est laborum.";
print &EncloseMessage($msg),"\n";
timethis(10000,'&EncloseMessage($msg);');
sub EncloseMessage {
my $txt=shift;
$txt =~ s{([\&<>]|(\s|\A)(\*)([^\*\n<>]+)\*(\s|\Z)|(\s|\A)(\*)([^\/\n<>]+)\/(\s|\Z))}{
my ($a,$b,$c,$d,$e) = ($1,$2,$3,$4,$5);
defined $c ? (
$c =~ /\*/ ? $b.'<b>'.$d.'</b>'.$e :
$c =~ /\// ? $b.'<i>'.$d.'</i>'.$e :
'/'
) :
$a =~ /\&/ ? '|' :
$a =~ /</ ? '&lt;' :
$a =~ />/ ? '&gt;' :
'\\'
}gmex;
$txt=~s/(\s|\A)\-(\-)?(\s|\Z)/$1\&\#8212\;$3/g;
# http://juick.com/last?page=2
# <a href="http://juick.com/last?page=2" rel="nofollow">juick.com</a>
while($txt=~s/(\s|\A)(https?:\/\/(?:www\.)?([^\/\s\n\"]+)\/?[^\s\n\"]*)/$1<a href="$2" rel="nofollow">$3<\/a>/g) {}
# _underline_
# <span class="u">underline</span>
while($txt=~s/(\s|\A)\_([^\_\n<>]+)\_(\s|\Z)/$1<span class="u">$2<\/span>$3/g) {}
# @username@jabber.org
# <a href="http://juick.com/username@jabber.org/">@username@jabber.org</a>
$txt=~s/\B\@([\w\-\.\@\|]+)\b/<a href="http:\/\/juick.com\/$1\/">\@$1<\/a>/g;
# #12345/67
# <a href="http://juick.com/12345#67">#12345/67</a>
while($txt=~s/(\s|\A)\#(\d+)\/(\d+)(\s|\Z)/$1<a href="http:\/\/juick.com\/$2\#$3">\#$2\/$3<\/a>$4/g) {}
# #12345
# <a href="http://juick.com/12345">#12345</a>
while($txt=~s/(\s|\A)\#(\d+)(\s|\Z)/$1<a href="http:\/\/juick.com\/$2">\#$2<\/a>$3/g) {}
$txt=~s/\n/<br\/>\n/g;
return $txt;
}