lazbarcodes: Refactoring of unit lbc_gs1

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8237 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-03-28 12:28:15 +00:00
parent 862deb52cc
commit 4801b18d59

View File

@ -1,13 +1,15 @@
unit lbc_gs1;
{ {
Based on Zint (done by Robin Stuart and the Zint team) Based on Zint (done by Robin Stuart and the Zint team)
http://github.com/zint/zint http://github.com/zint/zint
and translation by TheUnknownOnes and translation by TheUnknownOnes
http://theunknownones.net http://theunknownones.net
Refactoring: W. Pamler
} }
unit lbc_gs1;
{$IFDEF FPC} {$IFDEF FPC}
{$mode objfpc}{$H+} {$mode objfpc}{$H+}
{$ENDIF} {$ENDIF}
@ -28,14 +30,9 @@ implementation
uses uses
lbc_helper; lbc_helper;
{ This code does some checks on the integrity of GS1 data. It is not intended function Between(a, a1, a2: Integer): Boolean;
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);
begin begin
ai_string := FormatFloat('(00)', ai_value); Result := (a >= a1) and (a <= a2);
end; end;
function gs1_verify(ASymbol: PZintSymbol; ASource: PByte; const src_len: Integer; function gs1_verify(ASymbol: PZintSymbol; ASource: PByte; const src_len: Integer;
@ -190,7 +187,7 @@ begin
if (data_length[i] = 0) then if (data_length[i] = 0) then
begin begin
{ No data for given AI } { 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; Result := ERROR_INVALID_DATA;
exit; exit;
end; end;
@ -215,47 +212,40 @@ begin
error_latch := 2; error_latch := 2;
end; end;
if ( ((ai_value[i] >= 100) and (ai_value[i] <= 179) ) or if Between(ai_value[i], 100, 179) or Between(ai_value[i], 1000, 1799) or
((ai_value[i] >= 1000) and (ai_value[i] <= 1799)) or Between(ai_value[i], 200, 229) or Between(ai_value[i], 2000, 2299) or
((ai_value[i] >= 200) and (ai_value[i] <= 229)) or Between(ai_value[i], 300, 309) or Between(ai_value[i], 3000, 3099) or
((ai_value[i] >= 2000) and (ai_value[i] <= 2299)) or Between(ai_value[i], 31, 36) or Between(ai_value[i], 310, 369)
((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))
)
then 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 begin
if (data_length[i] <> 6) then if (data_length[i] <> 6) then
error_latch := 1; error_latch := 1;
end; end;
if ( ((ai_value[i] >= 370) and (ai_value[i] <= 379)) or if Between(ai_value[i], 370, 379) or Between(ai_value[i], 3700, 3799) then
((ai_value[i] >= 3700) and (ai_value[i] <= 3799)) )
then
error_latch := 2; error_latch := 2;
if (ai_value[i] >= 410) and (ai_value[i] <= 415) then if Between(ai_value[i], 410, 415) then
begin begin
if (data_length[i] <> 13) then if (data_length[i] <> 13) then
error_latch := 1; error_latch := 1;
end; end;
if ( ((ai_value[i] >= 4100) and (ai_value[i] <= 4199)) or if Between(ai_value[i], 4100, 4199) or
((ai_value[i] >= 700) and (ai_value[i] <= 703)) or Between(ai_value[i], 700, 703) or
((ai_value[i] >= 800) and (ai_value[i] <= 810)) or Between(ai_value[i], 800, 810) or
((ai_value[i] >= 900) and (ai_value[i] <= 999)) or Between(ai_value[i], 900, 999) or
((ai_value[i] >= 9000) and (ai_value[i] <= 9999)) ) Between(ai_value[i], 9000, 9999)
then then
error_latch := 2; error_latch := 2;
if ((error_latch < 4) and (error_latch > 0)) then if ((error_latch < 4) and (error_latch > 0)) then
begin begin
{ error has just been detected: capture AI } { error has just been detected: capture AI }
itostr(ai_string, ai_value[i]); ai_string := FormatFloat('(00)', ai_value[i]);
Inc(error_latch, 4); Inc(error_latch, 4);
end; end;
end; end;