diff options
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r-- | lib/VNDB/Func.pm | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index f3f9d009..a693e1de 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -7,7 +7,13 @@ use YAWF ':html'; use Exporter 'import'; use POSIX 'strftime', 'ceil', 'floor'; use VNDBUtil; -our @EXPORT = (@VNDBUtil::EXPORT, qw| liststat clearfloat cssicon tagscore mt minage |); +our @EXPORT = (@VNDBUtil::EXPORT, qw| liststat clearfloat cssicon tagscore mt minage fil_parse fil_serialize |); + + +# three ways to represent the same information +our $fil_escape = '_ !"#$%&\'()*+,-./:;<=>?@[\]^`{}~'; +our @fil_escape = split //, $fil_escape; +our %fil_escape = map +($fil_escape[$_], $_), 0..$#fil_escape; # Argument: hashref with rstat and vstat @@ -89,5 +95,25 @@ sub minage { } +sub fil_parse { + return { map { + my($f, $v) = split /-/, $_, 2; + my @v = split /,/, $v; + s/_([0-9]{2})/$1 > $#fil_escape ? '' : $fil_escape[$1]/eg for(@v); + $f => @v > 1 ? \@v : @v + } split /\./, scalar shift }; +} + + +sub fil_serialize { + my $fil = shift; + my $e = qr/([\Q$fil_escape\E])/; + return join '.', map { + my @v = ref $fil->{$_} ? @{$fil->{$_}} : ($fil->{$_}); + s/$e/_$fil_escape{$1}/g for(@v); + $_.'-'.join ',', @v + } keys %$fil; +} + 1; |