diff options
author | Yorhel <git@yorhel.nl> | 2010-11-28 10:45:43 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-11-28 10:45:43 +0100 |
commit | e27071f4110c6a93ef140b2d3dde331194917616 (patch) | |
tree | 269a8479ebe7a1b56480fae45b97ff5f30b728ad /lib/VNDB/Func.pm | |
parent | afa8f6cb619fd59d164d15d12249560706878639 (diff) | |
parent | 5bfd8f4559f2ce54332d28ac767619c020b151dc (diff) |
Merge branch 'beta'
Conflicts:
lib/VNDB/Handler/Discussions.pm
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r-- | lib/VNDB/Func.pm | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index f3f9d009..65b66f9e 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[$_], sprintf '%02d', $_), 0..$#fil_escape; # Argument: hashref with rstat and vstat @@ -89,5 +95,31 @@ sub minage { } +# arguments: $filter_string, @allowed_keys +sub fil_parse { + my $str = shift; + my %keys = map +($_,1), @_; + my %r; + for (split /\./, $str) { + next if !/^([a-z0-9_]+)-([a-zA-Z0-9_~]+)$/ || !$keys{$1}; + my($f, $v) = ($1, $2); + my @v = split /~/, $v; + s/_([0-9]{2})/$1 > $#fil_escape ? '' : $fil_escape[$1]/eg for(@v); + $r{$f} = @v > 1 ? \@v : $v[0] + } + return \%r; +} + + +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; |