summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoryorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b>2008-06-15 10:34:51 +0000
committeryorhel <yorhel@1fe2e327-d9db-4752-bcf7-ef0cb4a1748b>2008-06-15 10:34:51 +0000
commitd600e72db73cc46f9fc647f99c1eb4b833a821e0 (patch)
treec6726a0074f80df62c976a3e675cc1ca0ce09c62 /lib
parentdfcfb4a402dcfbc1b1873c5ead08584c3e71a5c6 (diff)
Small improvements in GTINType, documentation update, and renai.us accepts the URL without the www prefix as well, which I prefer
git-svn-id: svn://vndb.org/vndb@29 1fe2e327-d9db-4752-bcf7-ef0cb4a1748b
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog1
-rw-r--r--lib/VNDB/Util/Tools.pm19
2 files changed, 10 insertions, 10 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 263e3f1c..ce648155 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -19,6 +19,7 @@ TODO:
- Dynamic loading, several bugfixes, and code cleanup for Multi
- Added 'School Life' category
- Added GTIN field to releases
+ - Added links to encubed and renai.us
1.16 - 2008-05-22
- Release dates in the current year or month without a specified day will
diff --git a/lib/VNDB/Util/Tools.pm b/lib/VNDB/Util/Tools.pm
index e537d5a2..44e3f588 100644
--- a/lib/VNDB/Util/Tools.pm
+++ b/lib/VNDB/Util/Tools.pm
@@ -71,25 +71,24 @@ sub AddHid {
sub GTINType { # returns 'JAN', 'EAN', 'UPC' or undef
- my $c = $_[0];
- return undef if $c !~ /^[0-9]{12,14}$/; # only GTIN-12, 13 and 14 codes (for now...)
- $c = ('0'x(14-length $c)) . $c; # pad with zeros
+ (my $c = $_[0]) =~ s/^0+//;
+ return undef if $c !~ /^[0-9]{12,13}$/; # only gtin-12 and 13
+ $c = ('0'x(13-length $c)) . $c; # pad with zeros
# calculate check digit according to
# http://www.gs1.org/productssolutions/barcodes/support/check_digit_calculator.html#how
my @n = reverse split //, $c;
- my $n=0;
- $n += $n[$_] * ($_ % 2 == 0 ? 1 : 3) for (1..$#n);
- $n = 10 - ($n % 10);
- return undef if $n != $n[0];
+ my $n = shift @n;
+ $n += $n[$_] * ($_ % 2 != 0 ? 1 : 3) for (0..$#n);
+ return undef if $n % 10 != 0;
# Do some rough guesses based on:
# http://www.gs1.org/productssolutions/barcodes/support/prefix_list.html
# and http://en.wikipedia.org/wiki/List_of_GS1_country_codes
local $_ = $c;
- return 'JAN' if /^04[59]/; # prefix code 450-459 & 490-499
- return 'UPC' if /^0(?:0[01]|0[6-9]|13|75[45])/; # prefix code 000-019 & 060-139 & 754-755
- return undef if /0(?:0[2-5]|2|97[789]|9[6-9])/; # some codes we don't want: 020–059 & 200-299 & 977-999
+ return 'JAN' if /^4[59]/; # prefix code 450-459 & 490-499
+ return 'UPC' if /^(?:0[01]|0[6-9]|13|75[45])/; # prefix code 000-019 & 060-139 & 754-755
+ return undef if /(?:0[2-5]|2|97[789]|9[6-9])/; # some codes we don't want: 020–059 & 200-299 & 977-999
return 'EAN'; # let's just call everything else EAN :)
}