1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "fxbarcode/oned/BC_OnedEANChecksum.h"
6 
7 #include "core/fxcrt/fx_extension.h"
8 
EANCalcChecksum(const ByteString & contents)9 int32_t EANCalcChecksum(const ByteString& contents) {
10   int32_t odd = 0;
11   int32_t even = 0;
12   size_t parity = 1;
13   for (size_t i = contents.GetLength(); i > 0; i--) {
14     if (parity % 2)
15       odd += FXSYS_DecimalCharToInt(contents[i - 1]);
16     else
17       even += FXSYS_DecimalCharToInt(contents[i - 1]);
18     parity++;
19   }
20   return (10 - (odd * 3 + even) % 10) % 10;
21 }
22