source: trunk/Packages/lazbarcodes/src/lbc_common.pas

Last change on this file was 123, checked in by chronos, 3 years ago
  • Added: QR code image visible in contact others tab. It can be saved as image to file.
File size: 2.0 KB
Line 
1unit lbc_common;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 SysUtils, Types, zint;
9
10function ustrlen(const AData: TByteDynArray): NativeInt;
11procedure ustrcpy(var ATarget: TByteDynArray; const ASource: TByteDynArray);
12procedure ustrcpy(var ATarget: TByteDynArray; const ASource: String);
13procedure uconcat(var ADest: TByteDynArray; const ASource: TByteDynArray);
14procedure uconcat(var ADest: TByteDynArray; const ASource: TCharDynArray);
15procedure uconcat(var ADest: TByteDynArray; const ASource: String);
16
17
18implementation
19
20{ Local replacement for strlen() with uint8_t strings }
21function ustrlen(const AData: TByteDynArray): NativeInt;
22var
23 i: NativeInt;
24begin
25 Result := High(AData) - Low(AData) + 1;
26 for i := Low(AData) to High(AData) do
27 if AData[i] = 0 then
28 begin
29 Result := i - Low(AData);
30 break;
31 end;
32end;
33
34{ Local replacement for strcpy() with uint8_t strings }
35procedure ustrcpy(var ATarget: TByteDynArray; const ASource: TByteDynArray);
36var
37 len: NativeInt;
38begin
39 len := ustrlen(ASource);
40 if len > 0 then
41 begin
42 Move(ASource[0], ATarget[0], Len+1);
43 ATarget[len] := 0; // Be sure we have zero terminal
44 end;
45end;
46
47procedure ustrcpy(var ATarget: TByteDynArray; const ASource: String);
48var
49 len: NativeInt;
50begin
51 len := Length(ASource);
52 if len > 0 then
53 begin
54 Move(ASource[1], ATarget[0], Len+1);
55 ATarget[len] := 0;
56 end;
57end;
58
59{ Concatinates dest[] with the contents of source[], copying /0 as well }
60procedure uconcat(var ADest: TByteDynArray; const ASource: TByteDynArray);
61var
62 j, n: NativeInt;
63begin
64 j := ustrlen(ADest);
65 n := ustrlen(ASource);
66 Move(ASource[0], ADest[j], n);
67 ADest[j+n] := 0;
68end;
69
70procedure uconcat(var ADest: TByteDynArray; const ASource: TCharDynArray);
71var
72 j, n: NativeInt;
73begin
74 j := ustrlen(ADest);
75 n := System.strlen(PChar(ASource));
76 Move(ASource[0], ADest[j], n);
77 ADest[j+n] := 0;
78end;
79
80procedure uconcat(var ADest: TByteDynArray; const ASource: String);
81begin
82 uconcat(ADest, PChar(ASource));
83end;
84
85end.
86
Note: See TracBrowser for help on using the repository browser.