Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/zxing-cpp/core/src/GTIN.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /* | |
| 2 * Copyright 2016 Nu-book Inc. | |
| 3 * Copyright 2016 ZXing authors | |
| 4 * Copyright 2020 Axel Waggershauser | |
| 5 */ | |
| 6 // SPDX-License-Identifier: Apache-2.0 | |
| 7 | |
| 8 #pragma once | |
| 9 | |
| 10 #include "Barcode.h" | |
| 11 #include "BarcodeFormat.h" | |
| 12 #include "ZXAlgorithms.h" | |
| 13 | |
| 14 #include <string> | |
| 15 | |
| 16 namespace ZXing::GTIN { | |
| 17 | |
| 18 template <typename T> | |
| 19 T ComputeCheckDigit(const std::basic_string<T>& digits, bool skipTail = false) | |
| 20 { | |
| 21 int sum = 0, N = Size(digits) - skipTail; | |
| 22 for (int i = N - 1; i >= 0; i -= 2) | |
| 23 sum += digits[i] - '0'; | |
| 24 sum *= 3; | |
| 25 for (int i = N - 2; i >= 0; i -= 2) | |
| 26 sum += digits[i] - '0'; | |
| 27 return ToDigit<T>((10 - (sum % 10)) % 10); | |
| 28 } | |
| 29 | |
| 30 template <typename T> | |
| 31 bool IsCheckDigitValid(const std::basic_string<T>& s) | |
| 32 { | |
| 33 return ComputeCheckDigit(s, true) == s.back(); | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * Evaluate the prefix of the GTIN to estimate the country of origin. See | |
| 38 * <a href="https://www.gs1.org/standards/id-keys/company-prefix"> | |
| 39 * https://www.gs1.org/standards/id-keys/company-prefix</a> and | |
| 40 * <a href="https://en.wikipedia.org/wiki/List_of_GS1_country_codes"> | |
| 41 * https://en.wikipedia.org/wiki/List_of_GS1_country_codes</a>. | |
| 42 * | |
| 43 * `format` required for EAN-8 (UPC-E assumed if not given) | |
| 44 */ | |
| 45 std::string LookupCountryIdentifier(const std::string& GTIN, const BarcodeFormat format = BarcodeFormat::None); | |
| 46 | |
| 47 std::string EanAddOn(const Barcode& barcode); | |
| 48 | |
| 49 std::string IssueNr(const std::string& ean2AddOn); | |
| 50 std::string Price(const std::string& ean5AddOn); | |
| 51 | |
| 52 } // namespace ZXing::GTIN |
