summaryrefslogtreecommitdiff
path: root/fxbarcode/oned/BC_OnedEANChecksum.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fxbarcode/oned/BC_OnedEANChecksum.cpp')
-rw-r--r--fxbarcode/oned/BC_OnedEANChecksum.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/fxbarcode/oned/BC_OnedEANChecksum.cpp b/fxbarcode/oned/BC_OnedEANChecksum.cpp
new file mode 100644
index 0000000000..744a60827e
--- /dev/null
+++ b/fxbarcode/oned/BC_OnedEANChecksum.cpp
@@ -0,0 +1,21 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "fxbarcode/oned/BC_OnedEANChecksum.h"
+
+#include "core/fxcrt/fx_extension.h"
+
+int32_t EANCalcChecksum(const CFX_ByteString& contents) {
+ int32_t odd = 0;
+ int32_t even = 0;
+ FX_STRSIZE parity = 1;
+ for (FX_STRSIZE i = contents.GetLength(); i > 0; i--) {
+ if (parity % 2)
+ odd += FXSYS_DecimalCharToInt(contents[i - 1]);
+ else
+ even += FXSYS_DecimalCharToInt(contents[i - 1]);
+ parity++;
+ }
+ return (10 - (odd * 3 + even) % 10) % 10;
+}