lazbarcodes: Further refactoring of lbc_maxicode.pas

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8232 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2022-03-26 12:35:13 +00:00
parent e8550cb6a8
commit c266571f54

View File

@ -99,8 +99,11 @@ const
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 32, 33, 34, 35, 36
);
type
TMaxiCodeword = array[0..143] of Integer;
var
maxi_codeword: array[0..143] of Integer;
maxi_codeword: TMaxiCodeword;
{ Handles error correction of primary message }
procedure maxi_do_primary_check;
@ -580,22 +583,15 @@ begin
Result := 0;
end;
{ Format structured primary for Mode 2 }
{ Format structured primary for Mode 2.
Returns FALSE if APostCode is not a numeric string. }
function maxi_do_primary_2(APostCode: String; ACountry, AService: Integer): Boolean;
var
postcode_number: Integer;
postcode_length: Integer;
i: Integer;
begin
for i := 1 to Length(APostCode) do
if not (APostCode[i] in ['0'..'9']) then
begin
Result := false;
break;
end;
postcode_length := Length(APostcode);
if (APostCode = '') or not TryStrToInt(APostCode, postcode_number) then
if (postcode_length = 0) or not TryStrToInt(APostCode, postcode_number) then
begin
Result := false;
exit;
@ -614,34 +610,6 @@ begin
Result := true;
end;
(*
procedure maxi_do_primary_2(APostCode: TCharDynArray; ACountry, AService: Integer);
var
postcode_length, postcode_num: Integer;
i: Integer;
begin
for i := 0 to 9 do
if (APostCode[i] < '0') or (APostcode[i] > '9') then
begin
APostCode[i] := #0;
break;
end;
postcode_length := System.StrLen(PChar(@APostCode[0]));
postcode_num := StrToInt(PChar(@APostCode[0]));
maxi_codeword[0] := ((postcode_num and $03) shl 4) or 2;
maxi_codeword[1] := ((postcode_num and $fc) shr 2);
maxi_codeword[2] := ((postcode_num and $3f00) shr 8);
maxi_codeword[3] := ((postcode_num and $fc000) shr 14);
maxi_codeword[4] := ((postcode_num and $3f00000) shr 20);
maxi_codeword[5] := ((postcode_num and $3c000000) shr 26) or ((postcode_length and $3) shl 4);
maxi_codeword[6] := ((postcode_length and $3c) shr 2) or ((ACountry and $3AC) shl 4);
maxi_codeword[7] := (ACountry and $fc) shr 2;
maxi_codeword[8] := ((ACountry and $300) shr 8) or ((AService and $f) shl 2);
maxi_codeword[9] := ((AService and $3f0) shr 4);
end; *)
{ Format structured primary for Mode 3 }
procedure maxi_do_primary_3(APostCode: String; ACountry, AService: Integer);
@ -676,43 +644,6 @@ begin
maxi_codeword[9] := ((AService and $3f0) shr 4);
end;
(*
procedure maxi_do_primary_3(APostCode: TByteDynArray; ACountry, AService: Integer);
var
i, len: Integer;
P: PChar;
begin
len := System.StrLen(PChar(@APostCode[0]));
to_upper(APostCode);
P := PChar(@APostcode[0]);
for i := 0 to len-1 do
begin
// (Capital) letters shifted to Code Set A values
if (P^ >= 'A') and (P^ <= 'Z') then
byte(P^) := byte(P^) - 64;
// Not a valid PostCode character
if (P^ = #27) or (P^ = #31) or (P^ = #33) or (P^ >= #59) then
P^ := ' ';
// Input characters lower than 27 (NUL - SUB) in Postcode are
// interpreted a capital letters in Code Set A (e.g. LF becomes 'J')
inc(P);
end;
maxi_codeword[0] := ((Ord(APostCode[5]) and $03) shl 4) or 3;
maxi_codeword[1] := ((Ord(APostCode[4]) and $03) shl 4) or ((Ord(APostCode[5]) and $3c) shr 2);
maxi_codeword[2] := ((Ord(APostCode[3]) and $03) shl 4) or ((Ord(APostCode[4]) and $3c) shr 2);
maxi_codeword[3] := ((Ord(APostCode[2]) and $03) shl 4) or ((Ord(APostCode[3]) and $3c) shr 2);
maxi_codeword[4] := ((Ord(APostCode[1]) and $03) shl 4) or ((Ord(APostCode[2]) and $3c) shr 2);
maxi_codeword[5] := ((Ord(APostCode[0]) and $03) shl 4) or ((Ord(APostCode[1]) and $3c) shr 2);
maxi_codeword[6] := ((Ord(APostCode[0]) and $3c) shr 2) or ((ACountry and $3) shl 4);
maxi_codeword[7] := (ACountry and $fc) shr 2;
maxi_codeword[8] := (((ACountry and $300) shr 8)) or ((AService and $f) shl 2);
maxi_codeword[9] := ((AService and $3f0) shr 4);
end;
*)
function maxicode(ASymbol: PZintSymbol; ASource: String): Integer;
var
i, j, mode, countrycode, service: Integer;
@ -726,12 +657,10 @@ var
servicestr: string[3];
local_source: String;
begin
mode := ASymbol^.Option_1;
local_source := ASource;
maxi_codeword := Default(TMaxiCodeword);
FillChar(maxi_codeword[0], SizeOf(maxi_codeword), 0);
mode := ASymbol^.Option_1;
{ mode is not specified }
if (mode <= 0) then
begin