[interchange-cvs] [SCM] Interchange branch, master, updated. bcf1ee92ace67afe84ee7ce96abad9809d98aeaa

Stefan Hornburg interchange-cvs at icdevgroup.org
Sat Jun 27 13:10:41 UTC 2009


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Interchange".

The branch, master has been updated
       via  bcf1ee92ace67afe84ee7ce96abad9809d98aeaa (commit)
      from  ba0d8b7d2d9692e2d60ac536c73fe52b966f56ec (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit bcf1ee92ace67afe84ee7ce96abad9809d98aeaa
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Sat Jun 27 15:10:22 2009 +0200

    ISBN check can be advised to accept ISBN-10 or ISBN-13 numbers only.

-----------------------------------------------------------------------

Summary of changes and diff:
 WHATSNEW-5.7            |    2 ++
 code/OrderCheck/isbn.oc |   18 ++++++++++++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/WHATSNEW-5.7 b/WHATSNEW-5.7
index 52dc6b8..4162584 100644
--- a/WHATSNEW-5.7
+++ b/WHATSNEW-5.7
@@ -181,6 +181,8 @@ Checks
 
 * Allow custom error messages for email_only check.
 
+* ISBN check can be advised to accept ISBN-10 or ISBN-13 numbers only.
+
 Jobs
 ----
 
diff --git a/code/OrderCheck/isbn.oc b/code/OrderCheck/isbn.oc
index 7b42a3c..29cd92c 100644
--- a/code/OrderCheck/isbn.oc
+++ b/code/OrderCheck/isbn.oc
@@ -1,17 +1,21 @@
-# Copyright 2008 Interchange Development Group
+# Copyright 2008,2009 Interchange Development Group
 # 
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 2 of the License, or
 # (at your option) any later version.  See the LICENSE file for details.
-# 
-# $Id: isbn.oc,v 1.2 2008-07-11 08:37:28 racke Exp $
 
 CodeDef isbn OrderCheck 1
 CodeDef isbn Description ISBN-10/ISBN-13 check digit verification
 CodeDef isbn Routine <<EOR
 sub {
-	my($ref, $var, $val) = @_;
+	my($ref, $var, $val, $msg) = @_;
+	my($len);
+
+	if ($msg =~ s/^\s*(10|13)\s*//) {
+		$len = $1;
+	}
+
 	$val =~ s/[^\dXx]//g;	# weed out non-digits
 	if ($val) {
 		my @digits = split("", $val);
@@ -21,6 +25,9 @@ sub {
 
 		if (@digits == 10 ) {
 			# ISBN-10 number
+			if ($len == 13) {
+				return (0, $var, errmsg("'%s' not a valid isbn-13 number", $val));
+			}
 			for(my $i=10; $i > 0; $i--) {
 		  		my $d = $digits[10 - $i];
 				if ($d =~ /[Xx]/) {
@@ -36,6 +43,9 @@ sub {
 			return ( $sum%11 ? 0 : 1, $var, '' );
 		} elsif (@digits == 13) {
 			# ISBN-13/EAN number
+			if ($len == 10) {
+				return (0, $var, errmsg("'%s' not a valid isbn-10 number", $val));
+			}
 			for (my $i = 0; $i < 12; $i++) {
 				if ($i % 2) {
 					$sum += 3 * $digits[$i];


hooks/post-receive
-- 
Interchange



More information about the interchange-cvs mailing list