diff --git a/components/lazbarcodes/src/lbc_gs1.pas b/components/lazbarcodes/src/lbc_gs1.pas index 494c06fa5..e32f1a6f9 100644 --- a/components/lazbarcodes/src/lbc_gs1.pas +++ b/components/lazbarcodes/src/lbc_gs1.pas @@ -1,13 +1,15 @@ -unit lbc_gs1; - { Based on Zint (done by Robin Stuart and the Zint team) http://github.com/zint/zint and translation by TheUnknownOnes http://theunknownones.net + + Refactoring: W. Pamler } +unit lbc_gs1; + {$IFDEF FPC} {$mode objfpc}{$H+} {$ENDIF} @@ -28,14 +30,9 @@ implementation uses lbc_helper; -{ This code does some checks on the integrity of GS1 data. It is not intended - to be bulletproof, nor does it report very accurately what problem was found - or where, but should prevent some of the more common encoding errors. - - wp: simplified a lot...} -procedure itostr(var ai_string: String; ai_value: Integer); +function Between(a, a1, a2: Integer): Boolean; begin - ai_string := FormatFloat('(00)', ai_value); + Result := (a >= a1) and (a <= a2); end; function gs1_verify(ASymbol: PZintSymbol; ASource: PByte; const src_len: Integer; @@ -190,7 +187,7 @@ begin if (data_length[i] = 0) then begin { No data for given AI } - strcpy(ASymbol^.errtxt, 'Empty data field in input data'); + ASymbol^.SetErrorText('Empty data field in input data'); Result := ERROR_INVALID_DATA; exit; end; @@ -215,47 +212,40 @@ begin error_latch := 2; end; - if ( ((ai_value[i] >= 100) and (ai_value[i] <= 179) ) or - ((ai_value[i] >= 1000) and (ai_value[i] <= 1799)) or - ((ai_value[i] >= 200) and (ai_value[i] <= 229)) or - ((ai_value[i] >= 2000) and (ai_value[i] <= 2299)) or - ((ai_value[i] >= 300) and (ai_value[i] <= 309)) or - ((ai_value[i] >= 3000) and (ai_value[i] <= 3099)) or - ((ai_value[i] >= 31) and (ai_value[i] <= 36)) or - ((ai_value[i] >= 310) and (ai_value[i] <= 369)) - ) + if Between(ai_value[i], 100, 179) or Between(ai_value[i], 1000, 1799) or + Between(ai_value[i], 200, 229) or Between(ai_value[i], 2000, 2299) or + Between(ai_value[i], 300, 309) or Between(ai_value[i], 3000, 3099) or + Between(ai_value[i], 31, 36) or Between(ai_value[i], 310, 369) then - error_latch := 2; + error_latch := 2; - if (ai_value[i] >= 3100) and (ai_value[i] <= 3699) then + if Between(ai_value[i], 3100, 3699) then begin if (data_length[i] <> 6) then error_latch := 1; end; - if ( ((ai_value[i] >= 370) and (ai_value[i] <= 379)) or - ((ai_value[i] >= 3700) and (ai_value[i] <= 3799)) ) - then + if Between(ai_value[i], 370, 379) or Between(ai_value[i], 3700, 3799) then error_latch := 2; - if (ai_value[i] >= 410) and (ai_value[i] <= 415) then + if Between(ai_value[i], 410, 415) then begin if (data_length[i] <> 13) then - error_latch := 1; + error_latch := 1; end; - if ( ((ai_value[i] >= 4100) and (ai_value[i] <= 4199)) or - ((ai_value[i] >= 700) and (ai_value[i] <= 703)) or - ((ai_value[i] >= 800) and (ai_value[i] <= 810)) or - ((ai_value[i] >= 900) and (ai_value[i] <= 999)) or - ((ai_value[i] >= 9000) and (ai_value[i] <= 9999)) ) + if Between(ai_value[i], 4100, 4199) or + Between(ai_value[i], 700, 703) or + Between(ai_value[i], 800, 810) or + Between(ai_value[i], 900, 999) or + Between(ai_value[i], 9000, 9999) then error_latch := 2; if ((error_latch < 4) and (error_latch > 0)) then begin { error has just been detected: capture AI } - itostr(ai_string, ai_value[i]); + ai_string := FormatFloat('(00)', ai_value[i]); Inc(error_latch, 4); end; end;