-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathLightCore.StringListA.pas
More file actions
100 lines (79 loc) · 2.15 KB
/
LightCore.StringListA.pas
File metadata and controls
100 lines (79 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
UNIT LightCore.StringListA;
{=============================================================================================================
2026.01.30
www.GabrielMoraru.com
Github.com/GabrielOnDelphi/Delphi-LightSaber/blob/main/System/Copyright.txt
==============================================================================================================
Ansi StringList class
=============================================================================================================}
INTERFACE
USES
System.SysUtils, System.AnsiStrings, Generics.Collections;
TYPE
{ ANSI TStringList }
AnsiTSL = TList<AnsiString>;
TAnsiTSL= class(AnsiTSL)
private
function GetTextStr: AnsiString;
procedure SetTextStr(const Value: AnsiString);
public
property Text: AnsiString read GetTextStr write SetTextStr;
end;
IMPLEMENTATION
const
AnsiCRLF: AnsiString = #13#10;
{ Parses a multi-line AnsiString and adds each line to the list.
Handles CR, LF, and CRLF line endings. }
procedure TAnsiTSL.SetTextStr(const Value: AnsiString);
var
P, Start: PAnsiChar;
S: AnsiString;
begin
Clear;
P:= Pointer(Value);
if P = nil then EXIT;
{ Fast path: scan for CR/LF characters directly }
while P^ <> #0 do
begin
Start:= P;
while NOT (P^ in [#0, #10, #13]) do
Inc(P);
SetString(S, Start, P - Start);
Add(S);
if P^ = #13 then Inc(P);
if P^ = #10 then Inc(P);
end;
end;
{ Concatenates all lines into a single AnsiString with CRLF line endings.
Note: Adds CRLF after the last line as well. }
function TAnsiTSL.GetTextStr: AnsiString;
var
i, Len, TotalSize: Integer;
P: PAnsiChar;
Line: AnsiString;
const
LineBreakLen = 2; { Length of #13#10 }
begin
{ Calculate total size needed }
TotalSize:= 0;
for i:= 0 to Count - 1 do
Inc(TotalSize, Length(Self[i]) + LineBreakLen);
SetString(Result, nil, TotalSize);
P:= Pointer(Result);
for i:= 0 to Count - 1 do
begin
Line:= Self[i];
Len:= Length(Line);
if Len > 0 then
begin
System.Move(Pointer(Line)^, P^, Len);
Inc(P, Len);
end;
{ Add CRLF }
P^:= #13;
Inc(P);
P^:= #10;
Inc(P);
end;
end;
end.