Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r72624 - sandbox/SOC/2011/checks/boost/checks
From: pbristow_at_[hidden]
Date: 2011-06-17 07:45:53


Author: pbristow
Date: 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
New Revision: 72624
URL: http://svn.boost.org/trac/boost/changeset/72624

Log:
First of template version commit.
(Now consistent line ending styles)
Added:
   sandbox/SOC/2011/checks/boost/checks/EANcheck.cpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/IBMCheck.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/UPCcheck.cpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/UPCcheck.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/VISACheck.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/adler.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/amex.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/crc.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/ean.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/fletcher.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/iban.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/isan.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/isbn_Vasconcelos.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/luhn.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/mastercard.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/upc.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp (contents, props changed)
   sandbox/SOC/2011/checks/boost/checks/visa.hpp (contents, props changed)

Added: sandbox/SOC/2011/checks/boost/checks/EANcheck.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/EANcheck.cpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,170 @@
+//! \file EANcheck.cpp
+
+// Copyright Paul A. Bristow 2011.
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+// European Article numbering
+
+// EAN check
+
+// EAN Symbol Specification Manual,
+// Universal Product Code, Uniform Code Council, Dayton, Ohio, USA.
+// M. Blocksma, Reading the Numbers, Penguin, New York 1989.
+// Joseph A Gallian, ACM Computing Surveys, 28(3), 504-517 (Sep 1996)
+// Section 2, page 505 example of Kelloggs Low fat Granola 03800013710 & check digit 5.
+// EAN-13 check is (
+// Example is 7 012345 678908
+// EAN-8 check is -(1, 2, 3, 4, 5, 6, 7) * (3,1,3,1,3,1,3,1,3) mod 10 == 0
+// eg -(1 * 3 + 2 * 1 * 3 * 3 + 4 * 1 + %* 3 + 6 * 1 + 7 * 3) mod 10
+//
+// Stephen Barnett, Discrete Mathematics, Numbers and Beyond, Addison-Wesley.
+// ISBN 0201342928 EAN 978 201 342925
+// EAN for books is based on the ISBN and begins with the digits 978,
+// and the next nine digits being the first nine digits of the ISBN,
+// finally an EAN-13 check decimal digit.
+
+#include <iostream> // For testing only.
+//using std::cout; // For testing only.
+//using std::endl; // For testing only.
+
+#include <string>
+//using std::string;
+#include <vector>
+//using std::vector;
+
+#include <cassert>
+
+#include "EANcheck.hpp" // Declarations of bool EANcheck(string s); & char EANcompute(string s);
+
+bool EANcheck(std::string s)
+{ // Check that a EAN 13 includes the correct check end digit.
+ if (s.size() != 13)
+ { // Must be exactly 12 decimal digits + one decimal check digit.
+ std::cout << "length is " << unsigned int(s.size()) << std::endl;
+ return false;
+ }
+ std::vector<int> v(13); // Exactly 13 requirement.
+ assert(v.size() == 13);
+ for (int i = 0; i < 13; i++)
+ {
+ if (isdigit(s[i]))
+ {
+ v[i] = s[i] - '0';
+ }
+ else
+ { // Unexpected character in string!
+ std::cout << " unexpected char " << s[i] << std::endl;
+ return false;
+ }
+ }
+ int check = (v[0] * 1 + v[1] * 3 + v[2] * 1 + v[3] * 3 + v[4] * 1 + v[5] * 3
+ + v[6] * 1 + v[7] * 3 + v[8] * 1 + v[9] * 3 + v[10] * 1 + v[11] * 3
+ + v[12] * 1); // the 13th decimal check digit.
+ //std::cout << check << std::endl;
+ check %= 10; // modulus 10 because must be a decimal check digit,
+ // (not X as ISBN system).
+ //std::cout << check << std::endl;
+ return (check == 0);
+} // bool EANcheck(string s)
+
+char EANcompute(std::string s)
+{ // Compute EAN check digit.
+ if (s.size() != 12)
+ { // Must be exactly 12 decimal digits.
+ std::cout << "EAN length is " << unsigned int(s.size()) << std::endl;
+ return false;
+ }
+ std::vector<int> v(13); // Exactly 12 digits required,
+ // but leave space for check digit too?
+ assert(v.size() == 13);
+
+ for (int i = 0; i < 12; i++)
+ {
+ if (isdigit(s[i]))
+ { // Convert ACSII digit chars to int.
+ v[i] = s[i] - '0';
+ }
+ else
+ { // Unexpected character in string!
+ std::cout << " unexpected char " << s[i] << std::endl;
+ return false;
+ }
+ }
+ int check = (v[0] * 1 + v[1] * 3 + v[2] * 1 + v[3] * 3 + v[4] * 1 + v[5] * 3
+ + v[6] * 1 + v[7] * 3 + v[8] * 1 + v[9] * 3 + v[10] * 1 + v[11] * 3
+ ); // decimal check digit.
+
+ //cout << check << endl;
+ check %= 10; // modulus 10 so can be a decimal digit.
+ check = (check != 0) ? 10 - check : 0;
+ //std::cout << check << std::endl;
+ return char(check + '0'); // ASCII '0' to '9'
+} // bool EANcompute(string s)
+
+bool EAN8check(std::string s)
+{ // Check that a EAN-8 string includes the correct check digit.
+ // Examples: EAN8check("12345670")
+ // EAN8check("00511728")
+ if (s.size() != 8)
+ { // Must be exactly 7 decimal digits & one decimal check digit.
+ std::cout << "length is " << unsigned int(s.size()) << "!" << std::endl;
+ return false;
+ }
+ std::vector<int> v(8); // Exactly 8 decimal digits required.
+ assert(v.size() == 8);
+ for (int i = 0; i < 8; i++)
+ {
+ if (isdigit(s[i]))
+ { // Convert ascii digit chars to int.
+ v[i] = s[i] - '0'; // Convert ascii digit chars to int.
+ }
+ else
+ { // Unexpected character in string!
+ std::cout << " unexpected char " << s[i] << std::endl;
+ return false;
+ }
+ }
+ int check = (v[0] * 3 + v[1] * 1 + v[2] * 3 + v[3] * 1 + v[4] * 3 + v[5] * 1 + v[6] * 3
+ + v[7] * 1 // the 8th decimal check digit.
+ );
+ //std::cout << check << std::endl;
+ check %= 10; // modulus 10 because must be a decimal check digit (not X as ISBN system).
+ //std::cout << check << std::endl;
+ return (check == 0);
+} // bool EANcheck(string s)
+
+char EAN8compute(std::string s)
+{ // Compute EAN-8 check digit.
+ if (s.size() != 7)
+ { // Must be exactly 7 decimal digits, because 8th will be the check digit.
+ std::cout << "EAN length is " << unsigned int(s.size()) << std::endl;
+ return false;
+ }
+ std::vector<int> v(7);// Exactly 7 digits required,
+ assert(v.size() == 7);
+ for (int i = 0; i < 7; i++)
+ {
+ if (isdigit(s[i]))
+ {
+ v[i] = s[i] - '0';
+ }
+ else
+ { // Unexpected character in string!
+ std::cout << " unexpected char " << s[i] << std::endl;
+ return false;
+ }
+ }
+ int check = - (
+ v[0] * 3 + v[1] * 1 + v[2] * 3 + v[3] * 1 + v[4] * 3 + v[5] * 1 + v[6] * 3
+ ); // decimal check digit.
+
+ //std::cout << check << std::endl;
+ check %= 10; // modulus 10 as must be be a decimal digit (not X as ISBN system).
+ //std::cout << check << std::endl;
+ return char(check + '0'); // ASCII '0' to '9'
+} // bool EANcompute(string s)
+
+// and bar code 2 in 5...

Added: sandbox/SOC/2011/checks/boost/checks/IBMCheck.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/IBMCheck.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,104 @@
+// IBM check used by MAstercard, VISA, and most other credit card companies.
+
+// Is an even/odd weighted code.
+
+// Digits in the even positions (numbering from the right) are multiplied by 2,
+// then reduced to a single digit (if > 9) by "casting out nines"
+// (subtracting 9, which is equivalent to adding the digits).
+// All digits are them summed
+// and a check digit added to make the result evenly divisble by 10.
+
+// EAN for books is based on the ISBN and begins with the digits 978,
+// and the next nine digits being the first nine digits of the ISBN,
+// finally an EAN-13 check decimal digit.
+
+#include <string>
+#include <vector>
+#include <cctype> // isdigit, isspace, tolower
+
+using std::string;
+using std::vector;
+
+using std::cout;
+using std::endl;
+
+bool IBMcheck(string s)
+{ // Check an existing IBM check string s
+ // which includes a check digit 0 to 9.
+ vector<int> v(16);
+ for (int i = 0; i < 16; i++)
+ { // Convert decimal digit characters in string to integers in vector.
+ if (isdigit(s[i]))
+ {
+ v[i] = s[i] - '0';
+ }
+ else if (toupper(s[i] == 'X'))
+ {
+ v[i] = 10;
+ }
+ else
+ { // give up! (assumes no whitespace or punctuation).
+ return false;
+ }
+ // cout << v[i] << ' ';
+ }
+ int check = 0;
+ for (int i = 0; i < 16; i++)
+ {
+ if ((i % 2) == 0)
+ { // even
+ v[i] *= 2;
+ if (v[i] > 9)
+ {
+ v[i] -= 9; // "casting out nines"
+ }
+ }
+ // else unchanged if odd.
+ check += v[i]; //
+ }
+ //cout << '\n' << check << endl;
+ check %= 10; // modulus 10
+ // cout << ' ' << check << endl;
+ return (check == 0); // true if check digit is correct.
+} // bool IBMcheck(string s)
+
+char IBMcompute(string s)
+{ // Compute check digit 0 to 9 for the string provided.
+ // Might allow other size if remove whitespace and punctutation?
+ vector<int> v(15); // To hold numeric values from character values in string s.
+ for (int i = 0; i < 15; i++)
+ {
+ if (isdigit(s[i]))
+ {
+ v[i] = s[i] - '0';
+ }
+ else
+ { // throw?
+ //return '?';
+ // ignore
+ }
+ // cout << v[i] << ' ';
+ }
+ int check = 0;
+ for (int i = 0; i < 15; i++)
+ {
+ if ((i % 2) == 0)
+ { // even
+ v[i] *= 2;
+ if (v[i] > 9)
+ {
+ v[i] -= 9; // "casting out nines"
+ }
+ }
+ // else unchanged if odd.
+ check += v[i]; //
+ }
+ // cout << '\n' << check << endl;
+
+ check %= 10; // modulus 10
+ // cout << ' ' << check << endl;
+ if (check == 0) return '0';
+ check = 10 - check;
+ return char(check + '0');
+} // char IBMcompute(string s)
+

Added: sandbox/SOC/2011/checks/boost/checks/UPCcheck.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/UPCcheck.cpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,96 @@
+//! \file UPCcheck.cpp
+
+// Copyright Paul A. Bristow 2011.
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// UPC check
+
+// Universal Product Code
+// UPC Symbol Specification Manual, Uniform Code Council, Dayton, Ohio, USA.
+// M. Blocksma, Reading the Numbers, Penguin, New York 1989.
+// Joseph A Gallian, ACM Computing Surveys, 28(3), 504-517 (Sep 1996)
+// Section 2, page 505 example of Kellogs Low fat Granola 03800013710 & check digit 5.
+
+// Shipping code adds a second using modulo 103 arithmetic.
+// USS-128 Uniform Symbology Specification, p5,
+// Uniform Code Couuncil, Ohio, USA. (1986)
+
+#include <iostream> // For testing only.
+using std::cout; // For testing only.
+using std::endl; // For testing only.
+#include <string>
+// using std::string;
+#include <vector>
+//using std::vector;
+#include <cassert>
+
+#include <boost/checks/UPCcheck.hpp> // Declarations of bool UPCcheck(string s);
+// & char UPCcompute(string s);
+
+bool UPCcheck(std::string s)
+{ // Check that a UPC includes the correct check digit.
+ if (s.size() != 12)
+ { // Must be exactly 11 decimal digits + one decimal check digit.
+ cout << "length is " << unsigned int(s.size()) << " ! but must be exactly 12."<< endl;
+ return false;
+ }
+ std::vector<int> v (12);
+ assert(v.size() == 12);
+ for (int i = 0; i < 12; i++)
+ {
+ char d = s[i];
+ if (isdigit(d))
+ {
+ int c = d - int('0');
+ //v.push_back(c);
+ v[i] = c;
+ }
+ else
+ { // Unexpected character in string!
+ cout << " Unexpected char " << s[i] << endl;
+ return false;
+ }
+ }
+ int check = (v[0] * 3 + v[1] * 1 + v[2] * 3 + v[3] * 1 + v[4] * 3 + v[5] * 1
+ + v[6] * 3 + v[7] * 1 + v[8] * 3 + v[9] * 1 + v[10] * 3
+ + v[11] * 1); // the 12th decimal check digit.
+ // cout << check << endl;
+ check %= 10; // modulus 10 because a decimal check digit.
+ //cout << check << endl;
+ return bool(check == 0);
+} // bool UPCcheck(string s)
+
+char UPCcompute(std::string s)
+{ // Compute UPC check digit.
+ if (s.size() != 11)
+ { // Must be exactly 11 decimal digits.
+ cout << "UPC length is " << unsigned int(s.size()) << "! but should be exactly 11." << endl;
+ return false;
+ }
+ std::vector<int> v (12);
+ assert(v.size() == 12); // Exactly 11 digits required,
+ // but leave one space for check digit too.
+ for (int i = 0; i < 10; i++)
+ {
+ if (isdigit(s[i]))
+ {
+ v[i] = s[i] - int('0');
+ }
+ else
+ { // Unexpected character in string!
+ cout << " unexpected char " << s[i] << endl;
+ return false;
+ }
+ }
+ int check = (v[0] * 3 + v[1] * 1 + v[2] * 3 + v[3] * 1 + v[4] * 3 + v[5] * 1
+ + v[6] * 3 + v[7] * 1 + v[8] * 3 + v[9] * 1 + v[10] * 3);
+ // cout <<"check int before mod " << check << endl;
+ check %= 10; // modulus 10 so can be a decimal digit.
+ check = (check != 0) ? 10 - check : 0;
+ // cout << check << endl;
+ return char(check + '0'); // ASCII '0' to '9'
+} // bool UPCcompute(string s)

Added: sandbox/SOC/2011/checks/boost/checks/UPCcheck.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/UPCcheck.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,21 @@
+//! \file UPCcheck.hpp
+
+// Copyright Paul A. Bristow 2011.
+
+// Use, modification and distribution are subject to the
+// Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt
+// or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// UPCcheck.hpp
+
+// Universal Product Code UPC check
+// UPC Symbol Specification Manual, Uniform Code Council, Dayton, Ohio, USA.
+// M. Blocksma, Reading the Numbers, Penguin, New York 1989.
+// Joseph A Gallian, ACM Computing Surveys, 28(3), 504-517 (Sep 1996)
+// Section 2
+
+#include <string>
+
+bool UPCcheck(std::string s);
+char UPCcompute(std::string s);

Added: sandbox/SOC/2011/checks/boost/checks/VISACheck.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/VISACheck.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,269 @@
+// IBM check used by Mastercard, VISA, and most other credit card companies.
+// Version using Joseph A. Gallian permutations, rather than 'casting out nines'
+// See Error Detection Methods, Joseph A. Gallian,
+// ACM computing Surveys, 28(3) 504-517 (Sep 1996)
+// ISSN 0360-0300
+
+// Is an even/odd weighted code.
+
+// Digits in the even positions (numbering from the right) are multiplied by 2,
+// then reduced to a single digit (if > 9) by "casting out nines"
+// (subtracting 9, which is equivalent to adding the digits).
+// All digits are them summed
+// and a check digit added to make the result evenly divisble by 10.
+
+#include <string>
+#include <vector>
+#include <cctype> // isdigit, isspace, tolower
+
+using std::string;
+using std::vector;
+
+using std::cout;
+using std::endl;
+
+int perm[10] =
+{ // J A Gallian & S Winters, (1988), Amer. Math. Monthly 95, 548-551.
+ // A. Ecker & G. Poch, Check Characeter system, Computing, 37, 277-301 (1986)
+ // if digit == 0, add 0, if digit is 1, add 2 to check.
+ 0, // s(0) = 0 page 506 section 3, Credit card scheme.
+ 2, // s(1) = 2
+ 4, // s(2) = 4
+ 6, // s(3) = 6
+ 8, // s(4) = 8
+ 1, // s(5) = 1
+ 3, // s(6) = 3
+ 5, // s(7) = 5
+ 7, // s(8) = 7
+ 9, // s(9) = 9
+};
+
+bool VISAcheck(string s)
+{ // Check an existing IBM check string s
+ // which includes a check digit 0 to 9.
+ // const int n = 8; // n-1 digits, plus 1 nth check digit.
+ const int n = int(s.size()); // including check digit, so do all n digits.
+ // cout << "Check n = " << n << endl;
+ // 16 for credit card numbers.
+ vector<int> v(n);
+ for (int i = 0; i < n; i++)
+ { // Convert decimal digit characters in string to integers in vector.
+ if (isdigit(s[i]))
+ {
+ v[i] = s[i] - '0';
+ }
+ else if (toupper(s[i] == 'X'))
+ {
+ v[i] = 10;
+ }
+ else
+ { // give up! (assumes no whitespace or punctuation).
+ return false;
+ }
+ //cout << v[i] << ' ';
+ }
+ //cout << endl;
+ int check = 0;
+ for (int i = 0; i < n; i++)
+ { // Assumes n (total including check digit) is even.
+ // Permute the even numbered digits instead if n is odd.
+ if ((i % 2) == 0)
+ { // i is even, odd numbered digits (counting 1, 2, 3 ... n) are permuted.
+ // cout << v[i] << ' ' << perm[v[i]] << endl;
+ check += perm[v[i]];
+ }
+ else
+ { // even numbered digits (counting 1, 2, 3 ... n) are unchanged.
+ // cout << v[i] << endl;
+ check += v[i]; //
+ }
+ }
+ // cout << '\n' << check << endl;
+ check %= 10; // modulus 10
+ // cout << ' ' << check << endl;
+ return (check == 0); // true if check digit is correct.
+} // bool IBMcheck(string s)
+
+char VISAcompute(string s)
+{ // Compute check digit 0 to 9 for the string provided.
+ // Might allow other size if remove whitespace and punctutation?
+// const int n = 8; // including check digit, so only do n-1 digits.
+ const int n = int(s.size() +1); // including check digit, so only do n-1 digits.
+ // cout << "compute n = " << n << endl;
+
+ vector<int> v(n-1); // To hold numeric values from character values in string s.
+ for (int i = 0; i < n-1; i++)
+ {
+ if (isdigit(s[i]))
+ {
+ v[i] = s[i] - '0';
+ }
+ else
+ { // throw?
+ //return '?';
+ // ignore
+ }
+ // cout << v[i] << ' ';
+ }
+ int check = 0;
+ for (int i = 0; i < n-1; i++)
+ { // Assumes n (total including check digit) is even.
+ // Permute the even numbered digits instead if n is odd.
+ if ((i % 2) == 0)
+ { // i is even, odd numbered digits (counting 1, 2, 3 ... n) are permuted.
+ // cout << v[i] << ' ' << perm[v[i]] << endl;
+ check += perm[v[i]]; // permutated.
+ }
+ else
+ { // even numbered digits (counting 1, 2, 3 ... n) are unchanged.
+ // cout << v[i] << endl;
+ check += v[i]; // unchanged.
+ }
+ }
+ // cout << "\nComputed check " << check << endl;
+ // cout << '\n' << check << endl;
+ check %= 10; // modulus 10
+ // cout << ' ' << check << endl;
+ if (check == 0) return '0';
+ check = 10 - check;
+ return char(check + '0');
+} // char IBMcompute(string s)
+
+/*
+
+
+Test j:\cpp\isbn\testisbn.cpp Thu Nov 28 09:46:29 2002
+VISAcheck("76592146")
+Check n = 8
+7 6 5 9 2 1 4 6
+7 5
+6
+5 1
+9
+2 4
+1
+4 8
+6
+
+40
+ 0
+true
+VISAcompute("7659214")
+compute n = 8
+7 5
+6
+5 1
+9
+2 4
+1
+4 8
+
+Computed check 34
+VISAcompute("7659214") 6
+Check n = 16
+5 8 1 8 0 0 6 1 9 1 1 4 0 0 2 7
+5 1
+8
+1 2
+8
+0 0
+0
+6 3
+1
+9 9
+1
+1 2
+4
+0 0
+0
+2 4
+7
+
+50
+ 0
+VISAcheck("5818006191140027") true
+compute n = 16
+5 1
+8
+1 2
+8
+0 0
+0
+6 3
+1
+9 9
+1
+1 2
+4
+0 0
+0
+2 4
+
+Computed check 43
+VISAcompute("581800619114002") 7
+Check n = 16
+4 4 1 7 1 2 3 4 5 6 7 8 9 1 1 2
+4 8
+4
+1 2
+7
+1 2
+2
+3 6
+4
+5 1
+6
+7 5
+8
+9 9
+1
+1 2
+2
+
+69
+ 9
+VISAcheck("4417123456789112") false
+compute n = 16
+4 8
+4
+1 2
+7
+1 2
+2
+3 6
+4
+5 1
+6
+7 5
+8
+9 9
+1
+1 2
+
+Computed check 67
+VISAcompute("441712345678911") 3
+Check n = 16
+4 4 1 7 1 2 3 4 5 6 7 8 9 1 1 3
+4 8
+4
+1 2
+7
+1 2
+2
+3 6
+4
+5 1
+6
+7 5
+8
+9 9
+1
+1 2
+3
+
+70
+ 0
+VISAcheck("4417123456789113") true
+Press any key to continue
+
+*/
\ No newline at end of file

Added: sandbox/SOC/2011/checks/boost/checks/adler.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/adler.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,21 @@
+// Boost checks/adler.hpp header file ------------------------------------//
+//! \file
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_ADLER_INCLUDED
+#define BOOST_ADLER_INCLUDED
+
+namespace boost {
+ namespace checks{
+
+
+
+} // namespace checks
+} // namespace boost
+
+#endif
+

Added: sandbox/SOC/2011/checks/boost/checks/amex.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/amex.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,20 @@
+/ Boost checks/amex.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_AMEX_INCLUDED
+#define BOOST_AMEX_INCLUDED
+
+
+namespace boost {
+ namespace checks{
+
+/* American express : use luhn algorithm */
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/checks_fwd.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,93 @@
+// Boost checks/checks_fwd.hpp header file //
+
+// (C) Copyright Pierre Talbot 2011
+
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+// Provides a (perhaps temporary) mainpage for standalone Doxygen.
+// This seems a convenient place to put this, but it could go somewhere else?
+
+/*!
+\file
+\brief Boost.Checks forward declaration of function signatures.
+\details This file can be used to copy a function signature,
+but is mainly provided for testing purposes.
+
+\mainpage
+
+\b Boost.Checks
+
+This is the standalone Doxygen front page of the Boost.Checks library.
+
+This library provides a collection of functions for validating and creating check digits.
+
+Most are primarily for checking the accuracy of short strings of typed input
+(though obviously also provides against a mis-scan
+by a device like a bar code or card reader, or transmission error).
+
+The well-known ISBN is a typical example.
+All single altered digits, most double altered digits,
+and all transpositions of two digits are caught,
+and the input rejected as an invalid ISBN.
+
+See Boost.Checks HTML Manual at
+
+ https://svn.boost.org/svn/boost/sandbox/SOC/2011/checks/doc/html/index.html
+
+and/or equivalent PDF Manual at:
+
+ https://svn.boost.org/svn/boost/sandbox/SOC/2011/checks/doc/checks.pdf
+
+Examples are in folder:
+
+ https://svn.boost.org/svn/boost/sandbox/SOC/2011/checks/libs/checks/example/
+
+and C++ include files are in folder:
+
+ https://svn.boost.org/svn/boost/sandbox/SOC/2011/checks/boost/checks/
+
+*/
+
+/*
+
+DELETE THIS AFTER READING!
+
+It is redundant for production of html and pdf output,
+but useful to allow just Doxygen manuals (no Quickbook text or indexing).
+
+Standalone Doxygen can provide a more convenient compact index of
+the classes, files, namespaces and functions.
+They provide the Doxygen comments, but not any text from Quickbook.
+
+These manuals are quickly produced using the Doxywizard GUI frontend.
+A suitable doxyfile holding the list of files to include etc
+is conveniently placed in a /doc/doxygen sub-folder.
+Selecting this as the working directory from which doxygen will run as Step 1,
+and the run tab, and "run doxygen' in Step 2 should generate
+an html with index.html in the /doxygen sub-folder.
+
+The mainpage should give a pointer to the full html and/or pdf versions
+that provide the full Quickbook generated information.
+
+I:/boost-sandbox/tools/quick_auto_dox_index/libs/quick_auto_dox_index/doc/html/index.html
+QuickBook Auto Doxygen Indexed Manual
+
+*/
+
+
+
+// Provides forward declaration of all Boost.Checks functions:
+
+bool ISBNcheck(string s);
+char ISBNcompute(string s);
+
+template <class In>
+bool Is_isbn10(In isbn_begin, In isbn_end);
+
+template <class In>
+char isbn10_check_digit(In isbn_begin, In isbn_end);
+
+

Added: sandbox/SOC/2011/checks/boost/checks/crc.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/crc.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,18 @@
+/// Boost checks/crc.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_CRC_INCLUDED
+#define BOOST_CRC_INCLUDED
+
+namespace boost {
+ namespace checks{
+
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/ean.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/ean.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,46 @@
+// Boost checks/ean.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_EAN_INCLUDED
+#define BOOST_EAN_INCLUDED
+
+namespace boost {
+ namespace checks{
+
+/** Check the validity of the European Article Numbering of size 8 (EAN-8) provided.
+*/
+template <class In>
+inline bool Is_ean8(In ean_begin, In ean_end){}
+
+/** Compute the check digit of the European Article Numbering of size 8 (EAN-8) provided.
+*/
+template <class In>
+inline char ean8_check_digit(In ean_begin, In ean_end){}
+
+/** Check the validity of the European Article Numbering of size 13 (EAN-13) provided.
+ * \tparam In Iterator which represents the bound of a sequence of character.
+ * \tparam Prefix Iterator which represents the bound of a sequence of EAN prefixes (GS1 country codes).
+ * \param [in] ean_begin Represents the beginning of the EAN sequence to check.
+ * \param [in] ean_end Represents one off the end of the EAN sequence to check.
+ * \param [in] ean_prefix_begin Represents the beginning of the prefixes sequence to allow. Default : null, all the prefixes are allowed.
+ * \param [in] ean_prefix_end Represents the ending of the prefixes sequence to allow. Default : null, all the prefixes are allowed.
+ * \pre ean_begin and ean_end are valid initialized iterators. If ean_prefix_begin and ean_prefix_end are passed as arguments, they must be valid initialized iterators.
+ * \post ean_begin, ean_end, ean_prefix_begin, and ean_prefix_end are unchanged.
+ * \return True if the EAN delimited by ean_begin and ean_end is a valid EAN of size 13 with a prefix
+ */
+template <class In, class Prefix>
+inline bool Is_ean13(In ean_begin, In ean_end, Prefix ean_prefix_begin = null, Prefix ean_prefix_end = null){}
+
+/** Compute the check digit of the European Article Numbering of size 13 (EAN-13) provided.
+*/
+template <class In>
+inline char ean13_check_digit(In ean_begin, In ean_end){}
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/fletcher.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/fletcher.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,19 @@
+// Boost checks/fletcher.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_FLETCHER_INCLUDED
+#define BOOST_FLETCHER_INCLUDED
+
+
+namespace boost {
+ namespace checks{
+
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/iban.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/iban.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,19 @@
+// Boost checks/iban.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_IBAN_INCLUDED
+#define BOOST_IBAN_INCLUDED
+
+
+namespace boost {
+ namespace checks{
+
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/isan.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/isan.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,19 @@
+// Boost checks/isan.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_ISAN_INCLUDED
+#define BOOST_ISAN_INCLUDED
+
+
+namespace boost {
+ namespace checks{
+
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/isbn_Vasconcelos.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/isbn_Vasconcelos.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,63 @@
+// Boost checks/isbn.hpp header file ------------------------------------//
+// (C) Copyright Murilo Adriano Vasconcelos 2011.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_ISBN_INCLUDED
+#define BOOST_ISBN_INCLUDED
+
+#include <string>
+
+namespace boost {
+
+/**
+ * This function checks if a `isbn' is a valid ISBN
+ */
+bool is_isbn(const std::string& isbn)
+{
+ if (isbn.size() != 10) return false;
+
+ int check = 0;
+ for (int i = 0; i < 9; ++i) {
+ if (!isdigit(isbn[i])) {
+ return false;
+ }
+
+ check += (10 - i) * isbn[i];
+ }
+
+ check += (isbn[9] == 'x' || isbn[9] == 'X') ? 10 : isbn[9];
+
+ return (check % 11 == 0);
+}
+
+/**
+ * This function computes the check digit for a given ISBN in `isbn'
+ */
+char isbn_check_digit(const std::string& isbn)
+{
+ int check = 0;
+ for (int i = 0; i < 9; ++i) {
+ if (!isdigit(isbn[i])) {
+ return false;
+ }
+
+ check += (10 - i) * isbn[i];
+ }
+
+ check += (isbn[9] == 'x' || isbn[9] == 'X') ? 10 : isbn[9];
+ check %= 11;
+
+ if (check == 0) {
+ return '0';
+ }
+ check = 11 - check;
+
+ return (check == 10) ? 'X' : (check + '0');
+}
+
+} // namespace boost
+
+#endif
\ No newline at end of file

Added: sandbox/SOC/2011/checks/boost/checks/luhn.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/luhn.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,19 @@
+// Boost checks/luhn.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_LUHN_INCLUDED
+#define BOOST_LUHN_INCLUDED
+
+
+namespace boost {
+ namespace checks{
+
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/mastercard.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/mastercard.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,20 @@
+// Boost checks/mastercard.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_MASTERCARD_INCLUDED
+#define BOOST_MASTERCARD_INCLUDED
+
+
+namespace boost {
+ namespace checks{
+
+/* Mastercard : use luhn algorithm */
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/upc.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/upc.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,62 @@
+// Boost checks/upc.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_UPC_INCLUDED
+#define BOOST_UPC_INCLUDED
+
+namespace boost {
+ namespace checks{
+
+/** Check the validity of the Universal Product Code category A (UPC-A) provided.
+ * \tparam Iterator which represents the beginning or the ending of a sequence of character
+ * \param [in] upc_begin Represents the beginning of the UPC sequence to check.
+ * \param [in] upc_end] Represents one off the end of the UPC sequence to check.
+ * \pre upc_begin and upc_end are valid initialized iterators. The length of the sequence should be of size 12 and the sequence should contains only digits.
+ * \post upc_begin and upc_end are unchanged.
+ * \result true if the UPC sequence is valid which it means that the check digit is equals to the last character. Otherwise false.
+ */
+template <class In>
+inline bool Is_upca(In upc_begin, In upc_end)
+{
+ In iter = upc_begin;
+ unsigned short checksum = 0, i;
+ for(i = 11; i>0; ++iter, --i)
+ {
+ if(iter == upc_end || !isdigit(*iter)) return false;
+ else checksum += (*iter % 2 == 0) ? *iter * 3 : *iter;
+ }
+ if( i != 0 || iter == upc_end) return false;
+ return (*(++iter) == (10 - checksum % 10) %10) && iter == end;
+}
+
+/** Compute the check digit of the Universal Product Code category A (UPC-A) provided
+ * /tparam Iterator which represents the beginning or the ending of a sequence of character.
+ * /param [in] upc_begin Represents the beginning of the UPC sequence to check.
+ * /param [in] upc_end Represents one off the end of the UPC sequence to check.
+ * /pre upc_begin and upc_end are valid initialized iterators. The length of the sequence should be of size 11 and the sequence should contains only digits.
+ * /post upc_begin and upc_end are unchanged.
+ * /result 0 if the check digit couldn't be calculated (Exemple : wrong size, ...). Otherwise, the check digit character between '0' and '9'.
+ */
+template <class In>
+inline char upca_check_digit(In upc_begin, In upc_end)
+{
+ In iter = upc_begin;
+ unsigned short checksum = 0, i;
+ for(i = 11; i>0; ++iter, --i)
+ {
+ if(iter == upc_end || !isdigit(*iter)) return false;
+ else checksum += (*iter % 2 == 0) ? *iter * 3 : *iter;
+ }
+ if( i != 0 || iter != upc_end) return false;
+ return (10 - checksum % 10) %10;
+}
+
+} // namespace checks
+} // namespace boost
+
+#endif // #define BOOST_UPC_INCLUDED
+

Added: sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/verhoeff.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,19 @@
+// Boost checks/verhoeff.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_VERHOEFF_INCLUDED
+#define BOOST_VERHOEFF_INCLUDED
+
+
+namespace boost {
+ namespace checks{
+
+
+} // namespace checks
+} // namespace boost
+
+#endif

Added: sandbox/SOC/2011/checks/boost/checks/visa.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/visa.hpp 2011-06-17 07:45:51 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,20 @@
+// Boost checks/visa.hpp header file ------------------------------------//
+// (C) Copyright Pierre Talbot 2011
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt
+// See http://www.boost.org for updates, documentation, and revision history.
+
+#ifndef BOOST_VISA_INCLUDED
+#define BOOST_VISA_INCLUDED
+
+
+namespace boost {
+ namespace checks{
+
+/* visa : use luhn algorithm */
+
+} // namespace checks
+} // namespace boost
+
+#endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk