-
Notifications
You must be signed in to change notification settings - Fork 3
/
uTLH.StringList.pas
1916 lines (1654 loc) · 62.8 KB
/
uTLH.StringList.pas
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
TetzkatLipHoka 2015-2019
uTLH: StringList
Last updated: 05/26/2019
}
{
CompareStrings - Compare two StringLists - True if content is equal
LowerCase - Convert to LowerCase
UpperCase - Convert to UpperCase
Remove - Remove all appearances of 'Text' in 'string', result is new string
Replace - Replace all appearances of 'Text' in 'string' with 'rText', result is new string
FusionStringList - Combine two Strings
FilterDublicateEntries - Remove dublicate lines from TStrings
FilterEmptyEntries - Remove empty lines from TStrings
AppendRowsWithOpenBrackets - Appends follow lines to previous as long as brackets ( ( , [ , { ) are opened
PrefixLineMatchingToNextLines - Appends follow lines to a line matching 'text'
AppendLineMatchingToPreviousLines - Appends a line matching 'text' to a number of previous lines
PrefixLineMatching - Prefix all lines matching 'mText' with 'Text'
PrefixLineNotMatching - Prefix all lines not matching 'mText' with 'Text'
AppendToLineMatching - Append 'Text' to all lines matching 'mText'
AppendToLineNotMatching - Append 'Text' to all lines not matching 'mText'
ClearLineMatching - Clear all lines matching 'mText' with 'Text'
ClearLineNotMatching - Clear all lines not matching 'mText' with 'Text'
AddLineNumbers - Append line numers to line start
PrefixLines - Append text to string-start
AppendToLines - Append text to string-end
ConvertSpacesToTabs - Convert TABs to given value of spaces
ConvertTabsToSpaces - Convert given value of spaces to TABs
RemoveTabsAndSpaces - Strip Tabs and ( dublicate ) spaces
TrimLineAfter - Remove any chars after amount of chars from start
TrimLineFromLeft - Remove amount of chars from start of the string( s )
TrimLineFromRight - Remove amount of chars from end of the string( s )
RemoveSpacesFromLineStart - Remove any blanks/spaces from line start( s )
RemoveSpacesFromLineEnd - Remove any blanks/spaces from line end( s )
BreakLine - Break lines/start new line before/after amount of chars
BreakLine - Break lines/start new line before/after happening of 'string'
RemoveLinesContaining - Remove lines containing given string
RemoveLinesNOTContaining - Remove lines not containing given string
RemoveLinesStartingWith - Remove lines starting with 'text'
RemoveLinesEndingWith - Remove lines ending with 'text'
ExtractFileName - Extracts Filename from String
FunctionsToInitVar - Convert function-declarations to InitVar-calls
FunctionsToRd_Functions - Convert function-declarations to Redirect-Declaration + Redirect-Functions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~TStringList Sorting~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SortNaturalAscending - Natural/Human sorting
SortNaturalDescending - Natural/Human sorting
SortRegularAscending - Delphi/Machinal sorting
SortRegularDescending - Delphi/Machinal sorting
}
{$WARN GARBAGE OFF}
{$IFNDEF TLH_OMIT_SECTIONS}
unit uTLH.StringList;
{$I uTLH.inc}
interface
uses
Classes
// {$IFNDEF UNICDOE},WSDLIntf{$ENDIF}
;
{$ENDIF TLH_OMIT_SECTIONS}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{$IF NOT Defined(TLH_IMPLEMENTATIONSECTION) AND NOT Defined(TLH_INITIALIZATIONSECTION) AND NOT Defined(TLH_FINALIZATIONSECTION)}
function CompareStrings( StrL, StrL2: TStrings; caseSensitive : boolean = false ):boolean; // True if similiar
function LowerCase( StrL : TStrings ): TStrings;
procedure LowerCase_( StrL : TStrings );
function UpperCase( StrL : TStrings ): TStrings;
procedure UpperCase_( StrL : TStrings );
function Remove( StrL : TStrings; Text : String; WildCard : Boolean = false; CaseSensitive : Boolean = false ): TStrings;
procedure Remove_( StrL : TStrings; Text : String; WildCard : Boolean = false; CaseSensitive : Boolean = false );
function Replace( StrL : TStrings; mText, RText : String; WildCard : Boolean = false; CaseSensitive : Boolean = false ): TStrings;
procedure Replace_( StrL : TStrings; mText, RText : String; WildCard : Boolean = false; CaseSensitive : Boolean = false );
function FusionStrings( StrL1, StrL2 : TStrings; Prefix{orAppend} : Boolean = false ) : TStrings;
procedure FusionStrings_( StrL1, StrL2 : TStrings; Prefix{orAppend} : Boolean = false );
function FilterDublicateEntries( StrL : TStrings; caseSensitive : boolean = False ) : TStrings;
procedure FilterDublicateEntries_( StrL : TStrings; caseSensitive : boolean = False );
function FilterEmptyEntries( StrL : TStrings ) : TStrings;
procedure FilterEmptyEntries_( StrL : TStrings );
procedure AppendRowsWithOpenBrackets( StrL : TStrings );
function PrefixLineMatchingToNextLines( StrL : TStrings; Text : String; FollowLines : integer; caseSensitive : boolean = false; WildCard : boolean = false ): TStrings;
procedure PrefixLineMatchingToNextLines_( StrL : TStrings; Text : String; FollowLines : integer; caseSensitive : boolean = false; WildCard : boolean = false );
function AppendLineMatchingToPreviousLines( StrL : TStrings; Text : String; Lines : integer; caseSensitive : boolean = false; WildCard : boolean = false ): TStrings;
procedure AppendLineMatchingToPreviousLines_( StrL : TStrings; Text : String; Lines : integer; caseSensitive : boolean = false; WildCard : boolean = false );
function PrefixLineMatching( StrL : TStrings; mText, text : string; WildCard : boolean = false; caseSensitive : boolean = false ): TStrings;
procedure PrefixLineMatching_( StrL : TStrings; mText, text : string; WildCard : boolean = false; caseSensitive : boolean = false );
function PrefixLineNotMatching( StrL : TStrings; mText, text : string; WildCard : boolean = false; caseSensitive : boolean = false ): TStrings;
procedure PrefixLineNotMatching_( StrL : TStrings; mText, text : string; WildCard : boolean = false; caseSensitive : boolean = false );
function ClearLineMatching( StrL : TStrings; mText : string; WildCard : boolean = false; caseSensitive : boolean = false ): TStrings;
procedure ClearLineMatching_( StrL : TStrings; mText : string; WildCard : boolean = false; caseSensitive : boolean = false );
function ClearLineNotMatching( StrL : TStrings; mText : string; WildCard : boolean = false; caseSensitive : boolean = false ): TStrings;
procedure ClearLineNotMatching_( StrL : TStrings; mText : string; WildCard : boolean = false; caseSensitive : boolean = false );
function AppendToLineMatching( StrL : TStrings; mText, text : string; WildCard : boolean = false; caseSensitive : boolean = false ): TStrings;
procedure AppendToLineMatching_( StrL : TStrings; mText, text : string; WildCard : boolean = false; caseSensitive : boolean = false );
function AppendToLineNotMatching( StrL : TStrings; mText, text : string; WildCard : boolean = false; caseSensitive : boolean = false ): TStrings;
procedure AppendToLineNotMatching_( StrL : TStrings; mText, text : string; WildCard : boolean = false; caseSensitive : boolean = false );
function AddLineNumbers( StrL : TStrings ): TStrings; overload;
procedure AddLineNumbers_( StrL : TStrings ); overload;
function AddLineNumbers( StrL : TStrings; StartValue : Integer; Decreasing : boolean = false ): TStrings; overload;
procedure AddLineNumbers_( StrL : TStrings; StartValue : Integer; Decreasing : boolean = false ); overload;
function PrefixLines( StrL : TStrings; Text : string ): TStrings;
procedure PrefixLines_( StrL : TStrings; Text : string );
function AppendToLines( StrL : TStrings; Text : string ): TStrings;
procedure AppendToLines_( StrL : TStrings; Text : string );
function ConvertSpacesToTabs( StrL : TStrings; value : Byte ): TStrings;
procedure ConvertSpacesToTabs_( StrL : TStrings; value : Byte );
function ConvertTabsToSpaces( StrL : TStrings; value : Byte ): TStrings;
procedure ConvertTabsToSpaces_( StrL : TStrings; value : Byte );
function RemoveTabsAndSpaces( StrL : TStrings ): TStrings;
procedure RemoveTabsAndSpaces_( StrL : TStrings );
function TrimLineAfter( StrL : TStrings; Value : Byte ): TStrings;
procedure TrimLineAfter_( StrL : TStrings; Value : Byte );
function TrimLineFromLeft( StrL : TStrings; Value : Byte ): TStrings;
procedure TrimLineFromLeft_( StrL : TStrings; Value : Byte );
function TrimLineFromRight( StrL : TStrings; Value : Byte ): TStrings;
procedure TrimLineFromRight_( StrL : TStrings; Value : Byte );
function BreakLine( StrL : TStrings; Value : integer; EndLess : boolean = false ): TStrings; overload;
procedure BreakLine_( StrL : TStrings; Value : integer; EndLess : boolean = false ); overload;
function BreakLine( StrL : TStrings; text : string; CaseSensitive : boolean = false; Before : boolean = false; EndLess : boolean = false ): TStrings; overload;
procedure BreakLine_( StrL : TStrings; text : string; CaseSensitive : boolean = false; Before : boolean = false; EndLess : boolean = false ); overload;
function RemoveSpacesFromLineStart( StrL : TStrings ): TStrings;
procedure RemoveSpacesFromLineStart_( StrL : TStrings );
function RemoveSpacesFromLineEnd( StrL : TStrings ): TStrings;
procedure RemoveSpacesFromLineEnd_( StrL : TStrings );
function RemoveLinesContaining( StrL : TStrings; Text : string; WildCard : boolean = False; caseSensitive : boolean = false ): TStrings;
procedure RemoveLinesContaining_( StrL : TStrings; Text : string; WildCard : boolean = False; caseSensitive : boolean = false );
function RemoveLinesNOTContaining( StrL : TStrings; Text : string; WildCard : boolean = False; caseSensitive : boolean = false ): TStrings;
procedure RemoveLinesNOTContaining_( StrL : TStrings; Text : string; WildCard : boolean = False; caseSensitive : boolean = false );
function RemoveLinesStartingWith( StrL : TStrings; Text : string; caseSensitive : boolean = false ): TStrings;
procedure RemoveLinesStartingWith_( StrL : TStrings; Text : string; caseSensitive : boolean = false );
function RemoveLinesEndingWith( StrL : TStrings; Text : string; caseSensitive : boolean = false ): TStrings;
procedure RemoveLinesEndingWith_( StrL : TStrings; Text : string; caseSensitive : boolean = false );
function ExtractFileName( StrL : TStrings ): TStrings;
procedure ExtractFileName_( StrL : TStrings );
procedure FunctionsToInitVar( StrL : TStrings );
procedure FunctionsToRd_Functions( StrL : TStrings );
function ReplaceStringsAreal( Text : TStrings; start, endN : integer; rText : string ): TStrings; overload;
procedure ReplaceStringsAreal_( Text : TStrings; start, endN : integer; rText : string ); overload;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~TStringList Sorting~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function SortNaturalAscending( StrL : TStrings; caseSensitive : boolean = false ): TStrings; overload;
function SortNaturalDescending( StrL : TStrings; caseSensitive : boolean = false ): TStrings; overload;
function SortRegularAscending( StrL : TStrings ): TStrings; overload;
function SortRegularDescending( StrL : TStrings ): TStrings; overload;
function SortNaturalAscending( StrL : TStringList; caseSensitive : boolean = false ): TStringList; overload;
function SortNaturalDescending( StrL : TStringList; caseSensitive : boolean = false ): TStringList; overload;
function SortRegularAscending( StrL : TStringList ): TStringList; overload;
function SortRegularDescending( StrL : TStringList ): TStringList; overload;
procedure SortNaturalAscending_( StrL : TStrings; caseSensitive : boolean = false ); overload;
procedure SortNaturalDescending_( StrL : TStrings; caseSensitive : boolean = false ); overload;
procedure SortRegularAscending_( StrL : TStrings ); overload;
procedure SortRegularDescending_( StrL : TStrings ); overload;
procedure SortNaturalAscending_( StrL : TStringList; caseSensitive : boolean = false ); overload;
procedure SortNaturalDescending_( StrL : TStringList; caseSensitive : boolean = false ); overload;
procedure SortRegularAscending_( StrL : TStringList ); overload;
procedure SortRegularDescending_( StrL : TStringList ); overload;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Tokenize
function AddTok( const S: TStrings; T: String; const B: Byte; caseSensitive : boolean = False; AllowDuplicates : boolean = false ): TStrings; overload;
function AddTok( const S: TStrings; T: String; const C: Char; caseSensitive : boolean = False; AllowDuplicates : boolean = false ): TStrings; overload;
function DelTok( const S: TStrings; const N1, N2: Integer; const B: Byte ): TStrings; overload;
function DelTok( const S: TStrings; const N1, N2: Integer; const C: Char ): TStrings; overload;
function DelTok( const S: TStrings; const N: Integer; const B: Byte ): TStrings; overload;
function DelTok( const S: TStrings; const N: Integer; const C: Char ): TStrings; overload;
function GetTok( const S: TStrings; const N1, N2: Integer; const B: Byte; IgnoreEmpty : boolean = true ): TStrings; overload;
function GetTok( const S: TStrings; const N1, N2: Integer; const C: Char; IgnoreEmpty : boolean = true ): TStrings; overload;
function GetTok( const S: TStrings; const N: Integer; const B: Byte; IgnoreEmpty : boolean = true ): TStrings; overload;
function GetTok( const S: TStrings; const N: Integer; const C: Char; IgnoreEmpty : boolean = true ): TStrings; overload;
function InsTok( const S : TStrings; T : string; N: Integer; const B: Byte ): TStrings; overload;
function InsTok( const S : TStrings; T : string; N: Integer; const C: Char ): TStrings; overload;
function PutTok( const S : TStrings; T : string; N: Integer; const B: Byte ): TStrings; overload;
function PutTok( const S : TStrings; T : string; N: Integer; const C: Char ): TStrings; overload;
function ExTok( const S : TStrings; T1, T2: Integer; const B: Byte ): TStrings; overload;
function ExTok( const S : TStrings; T1, T2: Integer; const C: Char ): TStrings; overload;
function MoveTok( const S : TStrings; T1, T2: Integer; const B: Byte ): TStrings; overload;
function MoveTok( const S : TStrings; T1, T2: Integer; const C: Char ): TStrings; overload;
function CloneTok( const S : TStrings; T1, T2: Integer; const B: Byte ): TStrings; overload;
function CloneTok( const S : TStrings; T1, T2: Integer; const C: Char ): TStrings; overload;
procedure AddTok_( S: TStrings; T: String; const B: Byte; caseSensitive : boolean = False; AllowDuplicates : boolean = false ); overload;
procedure AddTok_( S: TStrings; T: String; const C: Char; caseSensitive : boolean = False; AllowDuplicates : boolean = false ); overload;
procedure DelTok_( S: TStrings; const N1, N2: Integer; const B: Byte ); overload;
procedure DelTok_( S: TStrings; const N1, N2: Integer; const C: Char ); overload;
procedure DelTok_( S: TStrings; const N: Integer; const B: Byte ); overload;
procedure DelTok_( S: TStrings; const N: Integer; const C: Char ); overload;
procedure GetTok_( S: TStrings; const N1, N2: Integer; const B: Byte; IgnoreEmpty : boolean = true ); overload;
procedure GetTok_( S: TStrings; const N1, N2: Integer; const C: Char; IgnoreEmpty : boolean = true ); overload;
procedure GetTok_( S: TStrings; const N: Integer; const B: Byte; IgnoreEmpty : boolean = true ); overload;
procedure GetTok_( S: TStrings; const N: Integer; const C: Char; IgnoreEmpty : boolean = true ); overload;
procedure InsTok_( S : TStrings; T : string; N: Integer; const B: Byte ); overload;
procedure InsTok_( S : TStrings; T : string; N: Integer; const C: Char ); overload;
procedure PutTok_( S : TStrings; T : string; N: Integer; const B: Byte ); overload;
procedure PutTok_( S : TStrings; T : string; N: Integer; const C: Char ); overload;
procedure ExTok_( S : TStrings; T1, T2: Integer; const B: Byte ); overload;
procedure ExTok_( S : TStrings; T1, T2: Integer; const C: Char ); overload;
procedure MoveTok_( S : TStrings; T1, T2: Integer; const B: Byte ); overload;
procedure MoveTok_( S : TStrings; T1, T2: Integer; const C: Char ); overload;
procedure CloneTok_( S : TStrings; T1, T2: Integer; const B: Byte ); overload;
procedure CloneTok_( S : TStrings; T1, T2: Integer; const C: Char ); overload;
{$IFEND TLH_IMPLEMENTATIONSECTION}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{$IFNDEF TLH_OMIT_SECTIONS}
implementation
uses
Math, StrUtils, SysUtils,
uTLH.Strings;
{$ENDIF TLH_OMIT_SECTIONS}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{$IF NOT Defined(TLH_INTERFACESECTION) AND NOT Defined(TLH_INITIALIZATIONSECTION) AND NOT Defined(TLH_FINALIZATIONSECTION)}
function CompareStrings( StrL, StrL2: TStrings; caseSensitive : boolean = false ):boolean; // True if similiar
var
i : Integer;
begin
result := False;
if ( StrL.Count = StrL2.Count ) AND ( StrL.Count < 1 ) then
begin
result := true;
Exit;
end
else if ( StrL.Count <> StrL2.Count ) OR ( StrL.Count < 1 ) then
Exit;
result := true;
for i := 0 to StrL.Count-1 do
begin
if ( caseSensitive ) then
begin
if ( StrL[ i ] <> StrL2[ i ] ) then
begin
result := false;
Break;
end;
end
else
begin
if ( SysUtils.LowerCase( StrL[ i ] ) <> SysUtils.LowerCase( StrL2[ i ] ) ) then
begin
result := false;
Break;
end;
end;
end;
end;
function LowerCase( StrL : TStrings ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
LowerCase_( result );
end;
procedure LowerCase_( StrL : TStrings );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := SysUtils.LowerCase( StrL[ i ] );
end;
function UpperCase( StrL : TStrings ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
UpperCase_( result );
end;
procedure UpperCase_( StrL : TStrings );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := SysUtils.UpperCase( StrL[ i ] );
end;
function Remove( StrL : TStrings; Text : String; WildCard : Boolean = false; CaseSensitive : Boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) or ( Text = '' ) then
Exit;
result.Assign( StrL );
Remove_( result, Text, Wildcard, CaseSensitive );
end;
procedure Remove_( StrL : TStrings; Text : String; WildCard : Boolean = false; CaseSensitive : Boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) or ( Text = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := uTLH.Strings.Remove( StrL[ i ], Text, WildCard, CaseSensitive );
end;
function Replace( StrL : TStrings; mText, RText : String; WildCard : Boolean = false; CaseSensitive : Boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) or ( mText = '' ) then
Exit;
result.Assign( StrL );
Replace_( result, mText, RText, Wildcard, CaseSensitive );
end;
procedure Replace_( StrL : TStrings; mText, RText : String; WildCard : Boolean = false; CaseSensitive : Boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) or ( mText = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := uTLH.Strings.Replace( StrL[ i ], mText, RText, WildCard, CaseSensitive );
end;
function FusionStrings( StrL1, StrL2 : TStrings; Prefix{orAppend} : Boolean = false ) : TStrings;
begin
result := TStringList.Create;
result.Assign( StrL1 );
FusionStrings_( result, StrL2, Prefix );
end;
procedure FusionStrings_( StrL1, StrL2 : TStrings; Prefix{orAppend} : Boolean = false );
var
i : Integer;
tmp : TStrings;
begin
if ( StrL1.Count = 0 ) and ( StrL2.Count > 0 ) then
begin
StrL1.Assign( StrL2 );
Exit;
end
else if ( StrL1.Count > 0 ) and ( StrL2.Count = 0 ) then
begin
// Result.Assign( StrL1 );
Exit;
end
else if ( StrL1.Count = 0 ) and ( StrL2.Count = 0 ) then
Exit;
tmp := TStringList.Create;
for i := 0 to Max( StrL1.Count, StrL2.Count )-1 do
begin
if ( i > Min( StrL1.Count, StrL2.Count )-1 ) then
begin
if ( i > StrL1.Count-1 ) then
tmp.Add( StrL2[ i ] )
else if ( i > StrL2.Count-1 ) then
tmp.Add( StrL1[ i ] );
end
else
begin
if Prefix then
begin
if ( RightStr( StrL1[ i ], 1 ) <> ' ' ) AND ( LeftStr( StrL2[ i ], 1 ) <> ' ' ) then
tmp.Add( StrL1[ i ] + ' ' + StrL2[ i ] )
else
tmp.Add( StrL1[ i ] + StrL2[ i ] );
end
else
begin
if ( RightStr( StrL2[ i ], 1 ) <> ' ' ) AND ( LeftStr( StrL1[ i ], 1 ) <> ' ' ) then
tmp.Add( StrL2[ i ] + ' ' + StrL1[ i ] )
else
tmp.Add( StrL2[ i ] + StrL1[ i ] );
end
end;
end;
StrL1.Assign( tmp );
tmp.free;
end;
function FilterDublicateEntries( StrL : TStrings; caseSensitive : boolean = False ) : TStrings;
begin
result := TStringList.Create;
result.Assign( StrL );
FilterDublicateEntries_( result, caseSensitive );
end;
procedure FilterDublicateEntries_( StrL : TStrings; caseSensitive : boolean = False );
var
a, b: integer;
begin
for a := StrL.count-1 downTo 0 do
begin
if ( StrL[ a ] = '' ) then
continue;
for b := a-1 downTo 0 do
begin
if ( a > StrL.count-1 ) OR ( b > StrL.count-1 ) then
continue;
if ( caseSensitive ) then
begin
if StrL[ a ] = StrL[ b ] then
StrL.Delete( b )
end
else if ( SysUtils.LowerCase( StrL[ a ] ) = SysUtils.LowerCase( StrL[ b ] ) ) then
StrL.Delete( b )
end;
end;
end;
function FilterEmptyEntries( StrL : TStrings ) : TStrings;
begin
result := TStringList.Create;
result.Assign( StrL );
FilterEmptyEntries_( result );
end;
procedure FilterEmptyEntries_( StrL : TStrings );
var
i : integer;
begin
for i := StrL.count-1 downTo 0 do
if ( StrL[ i ] = '' ) OR ( StrL[ i ] = DupeString( ' ', Length( StrL[ i ] ) ) ) then
StrL.Delete( i )
end;
procedure AppendRowsWithOpenBrackets( StrL : TStrings );
var
N, E, G, i : integer;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure CountBrackets( text : string );
var
i : integer;
begin
for i := {$IF CompilerVersion >= 24}Low(text){$ELSE}1{$IFEND} to {$IF CompilerVersion >= 24}High(text){$ELSE}Length(text){$IFEND} do
begin
if ( text[ i ] = '(' ) then
inc( N );
if ( text[ i ] = '[ ' ) then
inc( E );
if ( text[ i ] = '{' ) then
inc( G );
if ( text[ i ] = ')' ) then
dec( N );
if ( text[ i ] = ' ]' ) then
dec( E );
if ( text[ i ] = '}' ) then
dec( G );
N := Max( 0, N );
E := Max( 0, E );
G := Max( 0, G );
end;
end;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin
N := 0;
E := 0;
G := 0;
if ( StrL.Text = '' ) or ( StrL.Count < 2 ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( i+1 > StrL.Count-1 ) then
break;
CountBrackets( StrL[ i ] );
while ( ( N > 0 ) or ( E > 0 ) or ( G > 0 ) ) AND ( i+1 < StrL.Count-1 ) do
begin
if ( RightStr( StrL[ i ], 1 ) <> ' ' ) then
StrL[ i ] := StrL[ i ] + ' ' + StrL[ i+1 ]
else
StrL[ i ] := StrL[ i ] + StrL[ i+1 ];
CountBrackets( StrL[ i+1 ] );
StrL.Delete( i+1 );
end;
end;
end;
function PrefixLineMatchingToNextLines( StrL : TStrings; Text : String; FollowLines : integer; caseSensitive : boolean = false; WildCard : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
PrefixLineMatchingToNextLines_( result, Text, FollowLines, caseSensitive, WildCard );
end;
procedure PrefixLineMatchingToNextLines_( StrL : TStrings; Text : String; FollowLines : integer; caseSensitive : boolean = false; WildCard : boolean = false );
var
i, j : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
if ( Text = '' ) or ( FollowLines < 1 ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( i+1 > StrL.Count-1 ) then
break;
if ( WildCard AND ( IsWm( StrL[ i ], Text, caseSensitive ) ) ) OR ( NOT WildCard AND uTLH.Strings.CompareStrings( StrL[ i ], Text, caseSensitive ) ) then
begin
for j := 1 to FollowLines do
begin
if ( i+1 > StrL.Count-1 ) then
break;
if ( RightStr( StrL[ i ], 1 ) <> ' ' ) AND ( LeftStr( StrL[ i+1 ], 1 ) <> ' ' ) then
StrL[ i ] := StrL[ i ] + ' ' + StrL[ i+1 ]
else
StrL[ i ] := StrL[ i ] + StrL[ i+1 ];
StrL.Delete( i+1 );
end;
end;
end;
end;
function AppendLineMatchingToPreviousLines( StrL : TStrings; Text : String; Lines : integer; caseSensitive : boolean = false; WildCard : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
AppendLineMatchingToPreviousLines_( result, Text, Lines, caseSensitive, WildCard );
end;
procedure AppendLineMatchingToPreviousLines_( StrL : TStrings; Text : String; Lines : integer; caseSensitive : boolean = false; WildCard : boolean = false );
var
i, j : integer;
tStrL : TStrings;
str : string;
begin
if ( StrL.Count = 0 ) then
Exit;
if ( Text = '' ) or ( Lines < 1 ) then
Exit;
tStrL := TStringList.Create;
for i := StrL.Count-1 downTo 0 do
begin
if ( WildCard AND ( IsWm( StrL[ i ], Text, caseSensitive ) ) ) OR ( NOT WildCard AND uTLH.Strings.CompareStrings( StrL[ i ], Text, caseSensitive ) ) then
begin
str := StrL[ i ];
for j := 1 to Lines do
begin
if ( i-j < 0 ) then
break;
if ( LeftStr( StrL[ i ], 1 ) <> ' ' ) AND ( RightStr( StrL[ i-j ], 1 ) <> ' ' ) then
str := StrL[ i-j ] + ' ' + str
else
str := StrL[ i-j ] + str;
end;
tStrL.Insert( 0, str )
end
else
tStrL.Insert( 0, StrL[ i ] );
end;
StrL.Assign( tStrL );
tStrL.free;
end;
function PrefixLineMatching( StrL : TStrings; mText, Text : string; WildCard : boolean = False; caseSensitive : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) OR ( mText = '' ) OR ( Text = '' ) then
Exit;
result.Assign( StrL );
PrefixLineMatching_( result, mText, text, WildCard, caseSensitive );
end;
procedure PrefixLineMatching_( StrL : TStrings; mText, Text : string; WildCard : boolean = False; caseSensitive : boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) OR ( mText = '' ) OR ( Text = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( ( WildCard ) AND ( IsWm( StrL[ i ], mText, caseSensitive ) ) ) OR ( ( NOT WildCard ) AND ( uTLH.Strings.CompareStrings( StrL[ i ], mText, caseSensitive ) ) ) then
StrL[ i ] := Text + StrL[ i ];
end;
end;
function PrefixLineNotMatching( StrL : TStrings; mText, Text : string; WildCard : boolean = False; caseSensitive : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) OR ( mText = '' ) OR ( Text = '' ) then
Exit;
result.Assign( StrL );
PrefixLineNotMatching_( result, mText, text, WildCard, caseSensitive );
end;
procedure PrefixLineNotMatching_( StrL : TStrings; mText, Text : string; WildCard : boolean = False; caseSensitive : boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) OR ( mText = '' ) OR ( Text = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( ( WildCard ) AND ( NOT IsWm( StrL[ i ], mText, caseSensitive ) ) ) OR ( ( NOT WildCard ) AND ( NOT uTLH.Strings.CompareStrings( StrL[ i ], mText, caseSensitive ) ) ) then
StrL[ i ] := Text + StrL[ i ];
end;
end;
function ClearLineMatching( StrL : TStrings; mText : string; WildCard : boolean = False; caseSensitive : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) OR ( mText = '' ) then
Exit;
result.Assign( StrL );
ClearLineMatching_( result, mText, WildCard, caseSensitive );
end;
procedure ClearLineMatching_( StrL : TStrings; mText : string; WildCard : boolean = False; caseSensitive : boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) OR ( mText = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( ( WildCard ) AND ( IsWm( StrL[ i ], mText, caseSensitive ) ) ) OR ( ( NOT WildCard ) AND ( uTLH.Strings.CompareStrings( StrL[ i ], mText, caseSensitive ) ) ) then
StrL[ i ] := '';
end;
end;
function ClearLineNotMatching( StrL : TStrings; mText : string; WildCard : boolean = False; caseSensitive : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) OR ( mText = '' ) then
Exit;
result.Assign( StrL );
ClearLineNotMatching_( result, mText, WildCard, caseSensitive );
end;
procedure ClearLineNotMatching_( StrL : TStrings; mText : string; WildCard : boolean = False; caseSensitive : boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) OR ( mText = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( ( WildCard ) AND ( NOT IsWm( StrL[ i ], mText, caseSensitive ) ) ) OR ( ( NOT WildCard ) AND ( NOT uTLH.Strings.CompareStrings( StrL[ i ], mText, caseSensitive ) ) ) then
StrL[ i ] := '';
end;
end;
function AppendToLineMatching( StrL : TStrings; mText, Text : string; WildCard : boolean = False; caseSensitive : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) OR ( mText = '' ) OR ( Text = '' ) then
Exit;
result.Assign( StrL );
AppendToLineMatching_( result, mText, text, WildCard, caseSensitive );
end;
procedure AppendToLineMatching_( StrL : TStrings; mText, Text : string; WildCard : boolean = False; caseSensitive : boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) OR ( mText = '' ) OR ( Text = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( ( WildCard ) AND ( IsWm( StrL[ i ], mText, caseSensitive ) ) ) OR ( ( NOT WildCard ) AND ( uTLH.Strings.CompareStrings( StrL[ i ], mText, caseSensitive ) ) ) then
StrL[ i ] := StrL[ i ] + Text;
end;
end;
function AppendToLineNotMatching( StrL : TStrings; mText, Text : string; WildCard : boolean = False; caseSensitive : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) OR ( mText = '' ) OR ( Text = '' ) then
Exit;
result.Assign( StrL );
AppendToLineNotMatching_( result, mText, text, WildCard, caseSensitive );
end;
procedure AppendToLineNotMatching_( StrL : TStrings; mText, Text : string; WildCard : boolean = False; caseSensitive : boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) OR ( mText = '' ) OR ( Text = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( ( WildCard ) AND ( NOT IsWm( StrL[ i ], Text, caseSensitive ) ) ) OR ( ( NOT WildCard ) AND ( NOT uTLH.Strings.CompareStrings( StrL[ i ], mText, caseSensitive ) ) ) then
StrL[ i ] := StrL[ i ] + Text;
end;
end;
function AddLineNumbers( StrL : TStrings ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
AddLineNumbers_( result );
end;
procedure AddLineNumbers_( StrL : TStrings );
begin
if ( StrL.Count = 0 ) then
Exit;
AddLineNumbers_( StrL, 1 );
end;
function AddLineNumbers( StrL : TStrings; StartValue : integer; Decreasing : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
AddLineNumbers_( result, StartValue, Decreasing );
end;
procedure AddLineNumbers_( StrL : TStrings; StartValue : integer; Decreasing : boolean = false );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
begin
if ( Decreasing ) then
StrL[ i ] := IntToStr( StartValue - i ) + StrL[ i ]
else
StrL[ i ] := IntToStr( StartValue + i ) + StrL[ i ];
end;
end;
function PrefixLines( StrL : TStrings; Text : string ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) or ( Text = '' ) then
Exit;
result.Assign( StrL );
PrefixLines_( result, Text );
end;
procedure PrefixLines_( StrL : TStrings; Text : string );
var
i : integer;
begin
if ( StrL.Count = 0 ) or ( Text = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := Text + StrL[ i ];
end;
function AppendToLines( StrL : TStrings; Text : string ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) or ( Text = '' ) then
Exit;
result.Assign( StrL );
AppendToLines_( result, Text );
end;
procedure AppendToLines_( StrL : TStrings; Text : string );
var
i : integer;
begin
if ( StrL.Count = 0 ) or ( Text = '' ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := StrL[ i ] + Text;
end;
function ConvertSpacesToTabs( StrL : TStrings; value : Byte ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
ConvertSpacesToTabs_( result, value );
end;
procedure ConvertSpacesToTabs_( StrL : TStrings; value : Byte );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := uTLH.Strings.ConvertSpacesToTabs( StrL[ i ], value );
end;
function ConvertTabsToSpaces( StrL : TStrings; value : Byte ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
ConvertTabsToSpaces_( result, value );
end;
procedure ConvertTabsToSpaces_( StrL : TStrings; value : Byte );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := uTLH.Strings.ConvertTabsToSpaces( StrL[ i ], value );
end;
function RemoveTabsAndSpaces( StrL : TStrings ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
RemoveTabsAndSpaces_( result );
end;
procedure RemoveTabsAndSpaces_( StrL : TStrings );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := uTLH.Strings.RemoveTabsAndSpaces( StrL[ i ] );
end;
function TrimLineAfter( StrL : TStrings; Value : Byte ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
TrimLineAfter_( result, Value );
end;
procedure TrimLineAfter_( StrL : TStrings; Value : Byte );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := uTLH.Strings.TrimLineAfter( StrL[ i ], Value );
end;
function TrimLineFromLeft( StrL : TStrings; Value : Byte ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
TrimLineFromLeft_( result, Value );
end;
procedure TrimLineFromLeft_( StrL : TStrings; Value : Byte );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := uTLH.Strings.TrimLineFromLeft( StrL[ i ], Value );
end;
function TrimLineFromRight( StrL : TStrings; Value : Byte ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
TrimLineFromRight_( result, Value );
end;
procedure TrimLineFromRight_( StrL : TStrings; Value : Byte );
var
i : integer;
begin
if ( StrL.Count = 0 ) then
Exit;
for i := 0 to StrL.Count-1 do
StrL[ i ] := uTLH.Strings.TrimLineFromRight( StrL[ i ], Value );
end;
function BreakLine( StrL : TStrings; Value : integer; EndLess : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
BreakLine_( result, Value, EndLess );
end;
procedure BreakLine_( StrL : TStrings; Value : integer; EndLess : boolean = false );
var
i : integer;
s : string;
tmp : TStrings;
begin
if ( StrL.Count = 0 ) then
Exit;
if ( Value = 0 ) or ( StrL.Text = '' ) then
Exit;
tmp := TStringList.Create;
for i := 0 to StrL.Count-1 do
begin
if ( Length( StrL[ i ] ) > Value ) then
begin
s := StrL[ i ];
if ( EndLess ) then
begin
while ( Length( s ) > Value ) do
begin
tmp.Add( LeftStr( s, Value ) );
s := uTLH.Strings.TrimLineFromLeft( s, Value );
end;
end
else
begin
tmp.Add( LeftStr( s, Value ) );
tmp.Add( uTLH.Strings.TrimLineFromLeft( s, Value ) );
end;
end
else
tmp.Add( StrL[ i ] );
end;
StrL.Assign( tmp );
tmp.free;
end;
function BreakLine( StrL : TStrings; text : string; CaseSensitive : boolean = false; Before : boolean = false; EndLess : boolean = false ): TStrings;
begin
result := TStringList.Create;
if ( StrL.Count = 0 ) then
Exit;
result.Assign( StrL );
BreakLine_( result, text, CaseSensitive, Before, EndLess );
end;
procedure BreakLine_( StrL : TStrings; text : string; CaseSensitive : boolean = false; Before : boolean = false; EndLess : boolean = false );
var
i, p : integer;
s : string;
tmp : TStrings;