diff options
Diffstat (limited to 'fxbarcode/oned/BC_OnedEAN13Writer.cpp')
-rw-r--r-- | fxbarcode/oned/BC_OnedEAN13Writer.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/fxbarcode/oned/BC_OnedEAN13Writer.cpp b/fxbarcode/oned/BC_OnedEAN13Writer.cpp index dddb9cc24d..e7642de56d 100644 --- a/fxbarcode/oned/BC_OnedEAN13Writer.cpp +++ b/fxbarcode/oned/BC_OnedEAN13Writer.cpp @@ -79,17 +79,16 @@ CFX_WideString CBC_OnedEAN13Writer::FilterContents( int32_t CBC_OnedEAN13Writer::CalcChecksum(const CFX_ByteString& contents) { int32_t odd = 0; int32_t even = 0; - FX_STRSIZE j = 1; - for (FX_STRSIZE i = 0; i < contents.GetLength(); i++) { - if (j % 2) { - odd += FXSYS_DecimalCharToInt(contents[i]); + 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]); + even += FXSYS_DecimalCharToInt(contents[i - 1]); } - j++; + parity++; } - int32_t checksum = 10 - (odd * 3 + even) % 10; - return checksum; + return (10 - (odd * 3 + even) % 10) % 10; } uint8_t* CBC_OnedEAN13Writer::EncodeWithHint(const CFX_ByteString& contents, |