|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r72622 - sandbox/SOC/2011/checks/boost/checks
From: pbristow_at_[hidden]
Date: 2011-06-17 07:22:35
Author: pbristow
Date: 2011-06-17 07:22:35 EDT (Fri, 17 Jun 2011)
New Revision: 72622
URL: http://svn.boost.org/trac/boost/changeset/72622
Log:
First of template version commit.
(others have inconsistent line ending styles, so can't add yet)
Added:
sandbox/SOC/2011/checks/boost/checks/EANcheck.hpp (contents, props changed)
sandbox/SOC/2011/checks/boost/checks/ISBN_PAB.hpp (contents, props changed)
sandbox/SOC/2011/checks/boost/checks/ISSN_PAB.hpp (contents, props changed)
Added: sandbox/SOC/2011/checks/boost/checks/EANcheck.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/EANcheck.hpp 2011-06-17 07:22:35 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,18 @@
+// EAN.hpp
+
+// European Article Numbering
+// similar to
+// 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, 506
+// 13 decimal digit code, like UPC
+// uses a two digits that identify the country in which the item was produced.
+// C Harmon & R Adams, Reading between the Lines, Helmers publishing NH (1989)
+// Stephen Barnett, discrete Mathematics, Numbers and Beyond, Addison-Wesley.
+// ISBN 0201342928 EAN 9 78201 342925
+
+#include <string>
+
+bool EANcheck(std::string s);
+char EANcompute(std::string s);
Added: sandbox/SOC/2011/checks/boost/checks/ISBN_PAB.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/ISBN_PAB.hpp 2011-06-17 07:22:35 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,113 @@
+// ISBN_PAB.hpp obselete version
+
+//! \file
+//! \brief Obselete versio of ISBN check and compute.
+
+// Boost checks/isbn_pab.hpp header file ------------------------------------//
+
+// (C) Copyright Paul A. Bristow, 2002, 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
+
+// The Standard Book Numbering Agency Ltd, London.
+// ISBN.org
+// Philip M. Tuchinsky, International Standard Book Numbers,
+// UMAP Journal 5(1985) 41-45, ISSN 0197-3622
+// ISO Standard International Standard Book Number 2108:1992.
+// http://www.isbn.org/standards/home/isbn/digitalworld.asp
+// Length of the ISBN String/Check Digit
+
+// In January 2005, the ISBN standard will expand the current 10-digit string of numbers to 13.
+// This action is being taken to increase the availability of new numbers
+// and to make the ISBN standard compatible with European standard numbering systems EAN13.
+// All ISBNs in the original pool of numbers will be prefaced
+// by the prefix "978" to accomplish this increase in digits.
+// All new ISBNs will be given a prefix "979",
+// allowing the agency to effectively "reuse" the current pool of ISBNs.
+
+
+//#include <iostream> // test only.
+//using std::cout;
+//using std::endl;
+
+#include <string>
+//using std::string;
+
+#include <vector>
+//using std::vector;
+
+#include <cctype>
+// using std::isdigit and std::tolower
+
+// Defines:
+bool ISBNcheck(string s);
+char ISBNcompute(string s);
+
+
+bool ISBNcheck(std::string s)
+{ // Check an existing ISBN string s
+ // which includes a check digit 0 to 9 or X (=11)
+ std::vector<int> v(10);
+ for (int i = 0; i < 10; i++)
+ {
+ if (std::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 = 10 * v[0] + 9 * v[1] + 8 * v[2] + 7 * v[3] + 6 * v[4]
+ + 5 * v[5] + 4 * v[6] + 3 * v[7] + 2 * v[8]
+ + 1 * v[9]; // check digit
+ // std::cout << ' ' << check << std::endl;
+ check %= 11; // modulus 11
+ // std::cout << ' ' << check << std::endl;
+ return (check == 0); // true if check digit is correct.
+} // bool ISBNcheck(std::string s)
+
+char ISBNcompute(std::string s)
+{ // Compute check digit 0 to 9 or X (=11) for the string provided.
+ if (s.size() != 9)
+ {
+ return -1; // Must be exactly 9 digits (to be a 10 digit ISBN)
+ }
+ // Might allow other size if remove whitespace and punctutation?
+ std::vector<int> v(9);
+ for (int i = 0; i < 9; i++)
+ {
+ if (std::isdigit(s[i]))
+ {
+ v[i] = s[i] - '0';
+ }
+ else if (std::toupper(s[i] == 'X'))
+ {
+ v[i] = 10;
+ }
+ else
+ { // throw?
+ return '?';
+ }
+ // cout << v[i] << ' ';
+ }
+ int check = 10 * v[0] + 9 * v[1] + 8 * v[2] + 7 * v[3] + 6 * v[4]
+ + 5 * v[5] + 4 * v[6] + 3 * v[7] + 2 * v[8];
+
+ // std::cout << '\n' << check << std::endl;
+
+ check %= 11; // modulus 11
+ // std::cout << ' ' << check << std::endl;
+ if (check == 0) return '0';
+ check = 11 - check;
+ return (check == 10) ? 'X' : char(check + '0');
+} // char ISBNcomputer(std::string s)
+
Added: sandbox/SOC/2011/checks/boost/checks/ISSN_PAB.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2011/checks/boost/checks/ISSN_PAB.hpp 2011-06-17 07:22:35 EDT (Fri, 17 Jun 2011)
@@ -0,0 +1,94 @@
+// ISSN.hpp
+
+// The Standard Book Numbering Agency Ltd, London.
+// Philip M. Tuchinsky, International Standard Book Numbers, UMAP Journal 5(1985) 41-45, ISSN 0197-3622
+// ISO Standard, International Standard Book Number 2108:1992.
+// http://www.issn.org:8080/English/pub/faqs/barcodes
+// EAN-13 codes start with 977, "land of serial publications"
+// for example ISSN 1144-875X GENCOD informations(Paris)
+// EAN-13 bar code is 9 771144 875007
+// ISSN Check digit, in this case X is removed from the ISSN,
+// 00 is price code (usually 00), 7 is EAN-13 check digit
+// and finally issue number 03 for March, for example.
+
+// Defines:
+bool ISSNcheck(string s);
+char ISSNcompute(string s);
+
+#include <iostream>
+#include <string>
+#include <vector>
+#include <cctype> // for isdigit and tolower
+
+using std::string;
+using std::vector;
+
+using std::cout; // test only.
+using std::endl;
+
+bool ISSNcheck(string s)
+{ // Check an existing ISSN string s
+ // which includes a check digit 0 to 9 or X (=11)
+ vector<int> v(8);
+ for (int i = 0; i < 8; i++)
+ {
+ 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 = 8 * v[0] + 7 * v[1] + 6 * v[2] + 5 * v[3] + 4 * v[4]
+ + 3 * v[5] + 2 * v[6] + 1 * v[7];
+ //cout << ' ' << check << endl;
+ check %= 11; // modulus 11
+ //cout << ' ' << check << endl;
+ return (check == 0); // true if check digit is correct.
+} // bool ISSNcheck(string s)
+
+char ISSNcompute(string s)
+{ // Compute check digit 0 to 9 or X (=11) for the string provided.
+ if (s.size() != 7)
+ {
+ return '?' ; // Must be exactly 7 digits (to be a 8 digit ISSN)
+ }
+ // Might allow other sizes if remove whitespace and punctutation?
+ vector<int> v(7);
+ for (int i = 0; i < 7; i++)
+ {
+ if (isdigit(s[i]))
+ {
+ v[i] = s[i] - '0';
+ }
+ else if (toupper(s[i] == 'X'))
+ {
+ v[i] = 10;
+ }
+ else
+ { // throw?
+ return '?';
+ }
+ // cout << v[i] << ' ';
+ }
+ int check = 8 * v[0] + 7 * v[1] + 6 * v[2] + 5 * v[3] + 4 * v[4] + 3 * v[5] + 2 * v[6];
+
+ check %= 11; // modulus 11
+ if (check == 0) return '0';
+ check = 11 - check;
+ return (check == 10) ? 'X' : char(check + '0');
+ // return 3 * v[0] + 4 * v[1] + 5 * v[2] + 6 * v[3] + 7 * v[4] + 8 * v[5] + 9 * v[6];
+ // L. Egghe & R. Rousseau, Mathmetical and Computer Modelling,
+ // 33 (2001), 943-955 ISSN 0895-7177 page 944,
+ // equation 5 - simpler version of equation 4, the ISO standard.
+} // char ISSNcomputer(string s)
+
+
+
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