-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathabArray.PRG
More file actions
2022 lines (1628 loc) · 66.1 KB
/
abArray.PRG
File metadata and controls
2022 lines (1628 loc) · 66.1 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
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
* {fr} abArray.prg
* =====================================================
* (c) Abaque SARL, 66 rue Michel Ange - 75016 Paris - France
* contact@FoxInCloud.com - http://foxincloud.com/ - +33 9 53 41 90 90
* {fr} -----------------------------------------------------
* {fr} Ce logiciel est distribué sous GNU General Public License, tel quel, sans aucune garantie
* {fr} Il peut être utilisé et/ou redistribué sans restriction
* {fr} Toute modification doit être reversée à la communauté
* {fr} La présente mention doit être intégralement reproduite dans toute copie même partielle
* {en} -----------------------------------------------------
* {en} This software is distributed under the terms of GNU General Public License, AS IS, without any warranty
* {en} It can be used and/or distributed without restriction
* {en} Any modification or improvement must be given for free to the community
* {en} This permission notice shall be entirely included in all copies or substantial portions of the Software
* =====================================================
#INCLUDE AB.H
AB()
return abUnitTests()
* ===================================================================
function aChars && {fr} Tabule les caractères d'une chaîne {en} splits characters of a string into an Array
lparameters ;
taResult; && @ {fr} Résultat {en} Result
, tcString && {fr} Chaîne à splitter {en} String to be splitted
external Array taResult && {fr} pour le gestionnaire de projet
local lnResult; && {fr} nombre de lignes du Résultat
, llResult;
, liChar
lnResult = 0
llResult = aClear(@m.taResult) and ga_Type_IsChar(m.tcString, .T.)
assert m.llResult message cAssertMsg(textmerge(icase(;
cLangUser() = 'fr', [Tableau attendu en premier paramètre : <<cL(m.taResult)>>, chaîne en 2nd <<cL(m.tcString)>> !],; && copy-paste this line to add another language support
[Array expected as 1st parameter: <<cL(m.taResult)>>, String as 2nd <<cL(m.tcString)>>!]; && Default: English
)))
if m.llResult
lnResult = lenc(m.tcString)
if m.lnResult > 0
dimension taResult[m.lnResult]
for liChar = 1 to m.lnResult
taResult[m.liChar] = substrc(m.tcString, m.liChar, 1)
endfor
endif
endif
return m.lnResult
endfunc
* ===================================================================
function aOfList && {fr} Tabule les membre d'une liste {en} splits items of a list into an Array
lparameters ;
taResult; && @ {fr} Résultat {en} Result
, tcList; && {fr} Liste {en} List
, tlStrings; && [.F.] {fr} Les éléments de la liste sont des chaînes, sinon des littéraux de tous types (défaut) {en} List elements are strings, else literals of any type (default)
tlStrings = lTrue(m.tlStrings)
local lnResult; && {fr} nombre de lignes du Résultat
, llResult;
, lcList;
, lnSep, liSep, liSep_;
, lcElt;
lnResult = .null.
llResult = aClear(@m.taResult);
and ga_Type_IsChar(m.tcList, .T.);
and varSet(@m.lcList, cStringsMasked(m.tcList));
and ',' $ m.lcList;
and .T.
assert m.llResult message cAssertMsg(textmerge(icase(;
cLangUser() = 'fr', [Tableau attendu en premier paramètre : <<cL(m.taResult)>>, liste en 2nd <<cL(m.tcList)>> !],; && copy-paste this line to add another language support
[Array expected as 1st parameter: <<cL(m.taResult)>>, List as 2nd <<cL(m.tcList)>>!]; && Default: English
)))
if m.llResult
lnResult = Occurs(',', m.lcList) + 1
dimension taResult[m.lnResult]
for lnSep = 0 to m.lnResult - 1
liSep = Iif(m.lnSep = 0, 0, Atc(',', m.lcList, m.lnSep))
liSep_ = Iif(m.lnSep = m.lnResult, 0, Atc(',', m.lcList, m.lnSep + 1))
lcElt = Alltrim(Iif(m.liSep_ > 0;
, Substrc(m.tcList, m.liSep + 1, m.liSep_ - m.liSep - 1);
, Substrc(m.tcList, m.liSep + 1);
))
taResult[m.lnSep + 1] = Iif(m.tlStrings, m.lcElt, Evaluate(m.lcElt))
endfor
endif
return m.lnResult
endfunc
* --------------------------------------
procedure aOfList_Test
local abUnitTest as abUnitTest of abDev.prg, laTest[1]
abUnitTest = newobject('abUnitTest', 'abDev.prg')
local array aa[1]
abUnitTest.Test(4, @m.aa, [1, "test", 'tset', .T.])
abUnitTest.assert(1, m.aa[1])
abUnitTest.assert("test", m.aa[2])
abUnitTest.assert("tset", m.aa[3])
abUnitTest.assert(.T., m.aa[4])
return m.abUnitTest.result()
endproc
* ===================================================================
function aCopy_ && {en} Copy an Array into another while making sure dimensions match
lparameters ;
taSrce; && @ {fr} Source des lignes copiées dans taDest {en} Array to copy into taDest
, taDest; && @ {fr} tableau résultat {en} Result Array
, nFirstSourceElement; && [1] {en} see Acopy() documentation
, nNumberElements; && [all] {en} see Acopy() documentation
, nFirstDestElement; && [1] {en} see Acopy() documentation
external Array taSrce, taDest && {fr} pour le gestionnaire de projet {en} for the project manager
local lnResult; && {fr} nombre de lignes du Résultat {en} number of lines of the Array taDest
, llResult;
lnResult = 0
* {fr} Si des tableaux ont bien été passés {en} if parameters are really Array
llResult = type('taDest',1) == 'A' and type('taSrce', 1) == 'A'
assert m.llResult message cAssertMsg(icase(;
cLangUser() = 'fr', 'Les deux paramètres taDest et taSrce doivent être des tableaux',; && copy-paste this line to add another language support
'The type of parameters taDest and taSrce must be Array'; && Default: English
))
if m.llResult
if Alen(taSrce, 2) > 0
dimension taDest[Alen(taSrce, 1), Alen(taSrce, 2)]
else
dimension taDest[Alen(taSrce)]
endif
lnResult = Pcount()
lnResult = ICase(;
m.lnResult = 2,;
Acopy(taSrce, taDest),;
m.lnResult = 3,;
Acopy(taSrce, taDest, m.nFirstSourceElement),;
m.lnResult = 4,;
Acopy(taSrce, taDest, m.nFirstSourceElement, m.nNumberElements),;
Acopy(taSrce, taDest, m.nFirstSourceElement, m.nNumberElements, m.nFirstDestElement);
)
endif
return m.lnResult
endfunc
* ===================================================================
function aAppend && {fr} Ajoute les lignes d'un Tableau à un autre {en} Appends line from an Array to another
lparameters ;
taDest; && @ {fr} Résultat {en} Result Array
, taSrce; && @ {fr} Source des lignes ajoutées à taDest {en} Array to append to taDest
, tlUnique; && [.F.] {fr} ne pas ajouter les lignes existantes {en} don't append lines that already exists in the result Array
, tlPrepend && [.F.] {fr} ajouter en début de Tableau {en} append at the beginning of the Array
external Array taDest, taSrce && {fr} pour le gestionnaire de projet {en} for the project manager
tlUnique = lTrue(m.tlUnique)
tlPrepend = lTrue(m.tlPrepend)
local lnResult; && {fr} nombre de lignes du Résultat {en} number of lines of the Array taDest
, llResult;
, lnRowsSrce, liRowSrce;
, lnRowsDest, liRowDest;
, lnColsSrce, llColsSrce, liColSrce;
, lnColsDest, llColsDest
lnResult = 0
* {fr} Si des tableaux ont bien été passés {en} if parameters are really Array
llResult = type('taDest',1) == 'A' and type('taSrce', 1) == 'A'
assert m.llResult message cAssertMsg(icase(;
cLangUser() = 'fr', 'Les deux paramètres taDest et taSrce doivent être des tableaux',; && copy-paste this line to add another language support
'The type of parameters taDest and taSrce must be Array'; && Default: English
))
if m.llResult
* {fr} Si le second Tableau a des lignes {en} If second Array belongs line(s)
lnRowsSrce = iif(laEmpty(@m.taSrce) , 0, alen(taSrce, 1))
lnRowsDest = iif(laEmpty(@m.taDest) , 0, alen(taDest, 1)) && {fr} alen(taDest,1) Fonctionne pour 1 et 2 dimensions {en} alen(taDest,1) is compatible for 1 and 2 dimensions
lnResult = m.lnRowsDest + m.lnRowsSrce
if m.lnRowsSrce > 0
* {fr} Ajuster le nombre de lignes et de colonnes du Résultat {en} adjusts the number of lines and columns for the result's Array
lnColsSrce = alen(taSrce, 2)
llColsSrce = m.lnColsSrce > 0
lnColsDest = alen(taDest, 2) && {fr} 0 si 1 dimension {en} 0 if dimension == 1
lnColsDest = max(m.lnColsDest, m.lnColsSrce)
llColsDest = m.lnColsDest > 0
if m.llColsDest
dimension taDest[m.lnResult, m.lnColsDest]
else
dimension taDest[m.lnResult]
endif
if m.tlPrepend
for m.liRowSrce = 1 to m.lnRowsSrce
ains(taDest, 1) && {fr} ajoute au début du Tableau {en} insert at the beginning of the Array
endfor
endif
* {fr} Pour chaque ligne du Tableau source {en} for each line of the Array
for m.liRowSrce = 1 to m.lnRowsSrce
liRowDest = iif(m.tlPrepend, m.liRowSrce, m.lnRowsDest + m.liRowSrce)
do case
case m.llColsDest and m.llColsSrce && {fr} les 2 tableaux ont 2 dimensions {en} each Array has 2 dimensions
for m.liColSrce = 1 to m.lnColsSrce
taDest[m.liRowDest, m.liColSrce] = taSrce[m.liRowSrce, m.liColSrce]
endfor
case m.llColsDest && {fr} Tableau destination à 2 dimensions, Tableau source à 1 dimension {en} target Array has 2 dimensions, source Array has only one
taDest[m.liRowDest, 1] = taSrce[m.liRowSrce]
otherwise && {fr} les 2 tableaux ont 1 dimension {en} each Array has one dimension
taDest[m.liRowDest] = taSrce[m.liRowSrce]
endcase
endfor
lnResult = iif(m.tlUnique, aDistinct(@m.taDest), m.lnResult)
endif
endif
return m.lnResult
* --------------------------------------
procedure aAbarray_Test_a && {fr} pour construire les Array de test {en} to build the test environment
lparameters ;
taTest; && {fr} premier Tableau {en} first Array
, taTest1 && {fr} second Tableau {en} second Array
dimension taTest[3,3]
taTest = .f.
taTest[1,1] = 1
taTest[1,2] = 2
taTest[1,3] = 3
taTest[2,1] = 4
taTest[2,2] = 5
taTest[2,3] = 6
taTest[3,1] = 7
taTest[3,2] = 8
taTest[3,3] = 9
dimension taTest1[3,3]
taTest1 = .f.
taTest1[1,1] = "A"
taTest1[1,2] = "B"
taTest1[1,3] = "C"
taTest1[2,1] = "D"
taTest1[2,2] = "E"
taTest1[2,3] = "F"
taTest1[3,1] = "G"
taTest1[3,2] = "H"
taTest1[3,3] = "I"
* -----------------------------------------------------------------
procedure aAppend_Test && {fr} Teste aAppend()
local abUnitTest as abUnitTest of abDev.prg
abUnitTest = newobject('abUnitTest', 'abDev.prg')
public Array laTest[3, 3], laTest1[3, 3] && {fr} PUBLIC pour l'examiner après test
abUnitTest.Test(6, @m.laTest, @m.laTest1)
abUnitTest.assert(6, alen(laTest, 1))
return m.abUnitTest.Result()
* ===================================================================
function aSubstract && {fr} Soustrait les éléments d'un Tableau à un autre {en} remove some elements from an Array to another
lparameters ;
taDest; && @ {fr} Résultat {en} Result
, taSrce && @ {fr} Tableau contenant les lignes à soustraire de taDest {fr} Array with lines to remove from taDest
external Array taDest, taSrce
local liResult, llResult, lnResult
lnResult = 0
llResult = type('taDest', 1) == 'A' and type('taSrce', 1) == 'A'
assert m.llResult message cAssertMsg(textmerge(icase(;
cLangUser() = 'fr', [deux tableaux attendus en paramètres],; && copy-paste this line to add another language support
[two Arrays expected as parameters]; && Default: English
)))
if m.llResult
lnResult = alen(taDest)
for liResult = m.lnResult to 1 step -1
if ascan(taSrce, taDest[m.liResult], 1, -1, 1, 7+8) > 0 && 7: case insensitive, EXACT ON
lnResult = m.lnResult - 1
adel(m.taDest, m.liResult)
endif
endfor
if m.lnResult = 0
aClear(@m.taDest)
else
dimension taDest[m.lnResult]
endif
endif
return m.lnResult
* -------------------------------------------------------------
procedure aSubstract_Test && {fr} Teste aSubstract()
local abUnitTest as abUnitTest of abDev.prg, laDest[1], laSrce[1]
abUnitTest = newobject('abUnitTest', 'abDev.prg')
alines(laDest, 'toto,tutu,junk,foo,bar', ',')
alines(laSrce, 'Tutu,fOo', ',')
abUnitTest.Test(3, @m.laDest, @m.laSrce)
abUnitTest.assert('toto', laDest[1])
abUnitTest.assert('junk', laDest[2])
abUnitTest.assert('bar', laDest[3])
return abUnitTest.Result()
* ===================================================================
function aFilter && {fr} Filtre les éléments d'un Tableau par un autre {en} Filters the elements of an Array by another Array
lparameters ;
taDest; && @ {fr} Résultat {en} result
, taSrce; && @ {fr} Tableau contenant les lignes filtrant taDest {en} Array with lines used to filter taDest
, tlExactOff; && [.F.] {fr} Comparer avec exact off {en} compare with exact off
, tlCase; && [.F.] {fr} Comparer en respectant la casse {en} case-sensitive comparison
, tlExclude && [.F.] {fr} Garder les éléments destination absents de la source {en} Keep destination elements that can't be found in source
external Array taDest, taSrce
local lnResult as integer; && {fr} dimension du Tableau résultat
, llResult as Boolean;
, liDest, luDest;
, lnSrce, liSrce;
, liCompare
lnResult = 0
llResult = .t.;
and type('taDest', 1) == 'A';
and alen(taDest, 2) <= 1;
and type('taSrce', 1) == 'A';
and alen(taSrce, 2) <= 1
assert m.llResult message cAssertMsg(textmerge(icase(;
cLangUser() = 'fr', [deux tableaux à une dimension attendus en 1er et 2ème paramètres],; && copy-paste this line to add another language support
[two one-dimensional Arrays expected as parameters #1 and 2]; && Default: English
)))
if m.llResult
lnResult = alen(taDest)
lnSrce = alen(taSrce)
liCompare = 0;
+ iif(lTrue(m.tlCase), 0, 1);
+ iif(lTrue(m.tlExactOff), 0, 2) + 4 && {fr} override SET EXACT setting
tlExclude = lTrue(m.tlExclude)
for liDest = m.lnResult to 1 step -1
luDest = taDest[m.liDest]
luDest = ascan(taSrce, m.luDest, 1, -1, 1, m.liCompare)
if iif(m.tlExclude, m.luDest > 0, m.luDest = 0)
lnResult = m.lnResult - 1
adel(m.taDest, m.liDest)
endif
endfor
if m.lnResult = 0
aClear(@m.taDest)
else
dimension taDest[m.lnResult]
endif
endif
return m.lnResult
endfunc
* -------------------------------------------------------------
procedure aFilter_Test && {fr} Teste aFilter()
local abUnitTest as abUnitTest of abDev.prg, laDest[1], laSrce[1]
abUnitTest = newobject('abUnitTest', 'abDev.prg')
alines(laDest, 'toto,tutu,junk,foo,bar', ',')
alines(laSrce, 'Tutu,fOo', ',')
abUnitTest.Test(2, @m.laDest, @m.laSrce)
abUnitTest.assert('tutu', laDest[1])
abUnitTest.assert('foo', laDest[2])
alines(laDest, 'toto,tutu,junk,foo,bar', ',')
alines(laSrce, 'Tutu,fOo', ',')
abUnitTest.Test(2, @m.laDest, @m.laSrce,,,.t.)
abUnitTest.assert('toto', laDest[1])
abUnitTest.assert('junk', laDest[2])
abUnitTest.assert('bar', laDest[3])
return abUnitTest.Result()
* ===================================================================
function laEmpty && {fr} Tableau inexistant ou vide {en} Array don't exists or empty
lparameters ta && @ {fr} Tableau à vérifier {en} Array to verify
return not type('ta', 1) == 'A' or ;
alen(ta) = 1 and vartype(ta[1]) == 'L' and not ta[1]
external Array ta && {fr} après RETURN pour éviter exécution
* -------------------------------------------------------------
procedure laEmpty_test
local abUnitTest as abUnitTest of abDev.prg;
, laTest[1]
abUnitTest = newobject('abUnitTest', 'abDev.prg')
abUnitTest.Test(.t., @m.laTest)
return abUnitTest.Result()
* ===================================================================
function aRowDel && {fr} Supprime PHYSIQUEMENT une ligne d'un Tableau {en} remove a line from an Array
lparameters ;
taResult; && @ {fr} Résultat {en} result
, tnRow && {fr} n° de ligne à supprimer {en} number of the line to remove
external Array taResult
local llResult, lnResult && {fr} par analogie avec aDel(), 1 si la ligne est bien supprimée, 0 sinon {en} like aDel(), 1 if the line is suppressed, otherwise 0
lnResult = 0
llResult = not type('taResult[1,2]') == 'U' ; && {fr} au moins 2 colonnes
and vartype(m.tnRow) == 'N' ;
and m.tnRow > 0 ;
and m.tnRow <= alen(taResult, 1)
assert m.llResult message cAssertMsg(icase(;
cLangUser() = 'fr', 'Paramètre(s) requis incorrect(s)',; && copy-paste this line to add another language support
'Parameters required not allowed'; && Default: English
))
if m.llResult
* {fr} Effacer la ligne
adel(taResult, m.tnRow)
* {fr} Redimensionner
lnResult = alen(taResult, 1) - 1
if m.lnResult = 0
aClear(@m.taResult)
else
dimension taResult[m.lnResult, Alen(taResult, 2)]
endif
endif
return m.lnResult
* ===================================================================
function aRowMove && {fr} Déplace une ligne dans un Tableau {fr} Moves one line inside an Array
lparameters ;
taResult; && @ {fr} Résultat {en} result
, tnFrom; && {fr} n° de ligne à déplacer {en} number for the line to move
, tnTo && {fr} n° de ligne destination {en} number for the target line
external Array taResult
local lnRow, lnCol, llCol, laResult[1], llResult
llResult = .t.;
and type('taResult', 1) = 'A';
and vartype(m.tnFrom) == 'N';
and vartype(m.tnTo) == 'N';
and not m.tnFrom = m.tnTo;
and between(m.tnFrom, 1, alen(taResult, 1));
and between(m.tnTo, 1, alen(taResult, 1))
assert m.llResult message cAssertMsg(icase(;
cLangUser() = 'fr', 'Paramètre(s) requis incorrect(s)',; && copy-paste this line to add another language support
'Parameters required not allowed'; && Default: English
))
if m.llResult
lnRow = alen(taResult, 1)
lnCol = alen(taResult, 2)
llCol = m.lnCol > 0
llResult = iif(m.llCol;
, acopy(taResult, laResult, aelement(taResult, m.tnFrom, 1), m.lnCol);
, acopy(taResult, laResult, m.tnFrom, 1);
) > 0
assert m.llResult
if m.llResult
adel(taResult, m.tnFrom)
ains(taResult, m.tnTo)
llResult = iif(m.llCol;
, acopy(laResult, taResult, 1, m.lnCol, aelement(taResult, m.tnTo, 1));
, acopy(laResult, taResult, 1, 1, m.tnTo);
) > 0
assert m.llResult
endif
endif
return m.llResult
* -------------------------------------------------------------
procedure aRowMove_test && {fr} Teste aRowMove()
local abUnitTest as abUnitTest of abDev.prg, laResult[1]
abUnitTest = newobject('abUnitTest', 'abDev.prg')
aRowMove_test_a1(@m.laResult)
abUnitTest.Test(.t., @m.laResult, 3, 1)
abUnitTest.assert('3', m.laResult[1])
abUnitTest.assert('1', m.laResult[2])
aRowMove_test_a1(@m.laResult)
abUnitTest.Test(.t., @m.laResult, 1, 3)
abUnitTest.assert('2', m.laResult[1])
abUnitTest.assert('1', m.laResult[3])
aRowMove_test_a2(@m.laResult)
abUnitTest.Test(.t., @m.laResult, 3, 1)
abUnitTest.assert('31', m.laResult[1, 1])
abUnitTest.assert('11', m.laResult[2, 1])
aRowMove_test_a2(@m.laResult)
abUnitTest.Test(.t., @m.laResult, 1, 3)
abUnitTest.assert('21', m.laResult[1, 1])
abUnitTest.assert('11', m.laResult[3, 1])
return abUnitTest.Result()
* -------------------------------------------------------------
function aRowMove_test_a1 && {fr} Tableau de test à 1 dimension
lparameters laResult && @ {fr} Tableau
external Array laResult
dimension laResult[6]
laResult[1] = '1'
laResult[2] = '2'
laResult[3] = '3'
laResult[4] = '4'
laResult[5] = '5'
laResult[6] = '6'
* -------------------------------------------------------------
function aRowMove_test_a2 && {fr} Tableau de test à 2 dimensions
lparameters laResult && @ {fr} Tableau
local lcResult
text TO lcResult NOSHOW PRETEXT 1+2
11 12
21 22
31 32
41 42
51 52
61 62
ENDTEXT
aLinesCols(@m.laResult, m.lcResult)
* ===================================================================
function aColDel && {fr} Supprime physiquement une Colonne d'un Tableau {en} remove one Column from an Array
lparameters ;
taResult; && @ {fr} Résultat {en} Result
, tnCol && {fr} n° de Colonne à supprimer {en} number of the Column to remove
external Array taResult
local lnRow, liRow, lnCol, llResult, lnResult && {fr} par analogie avec aDel(), 1 si la Colonne est bien supprimée, 0 sinon {en} like aDel() return 1 if the Column is successfull removed, otherwise 0
lnResult = 0
llResult = .t.;
and not type('taResult[1,2]') == 'U' ; && {fr} au moins 2 colonnes
and vartype(m.tnCol) == 'N' ;
and between(m.tnCol, 1, alen(taResult, 2))
assert m.llResult message cAssertMsg(icase(;
cLangUser() = 'fr', 'Paramètre(s) requis incorrect(s)',; && copy-paste this line to add another language support
'Parameters required not allowed'; && Default: English
))
if m.llResult
* {fr} Convertir le Tableau en mono-dimensionnel
lnRow = alen(taResult, 1)
lnCol = alen(taResult, 2)
dimension taResult[m.lnRow * m.lnCol]
* {fr} Supprimer physiquement les cellules de la Colonne à enlever
for m.liRow = m.lnRow to 1 step -1
lnResult = adel(taResult, (m.liRow - 1) * m.lnCol + m.tnCol)
if m.lnResult = 0
exit
endif
endfor
* {fr} Rétablir le Tableau en 2 dimensions
if m.lnResult > 0
dimension taResult[m.lnRow, m.lnCol - 1]
endif
endif
return m.lnResult
* --------------------------------------
procedure aColDel_Test
local abUnitTest as abUnitTest of abDev.prg, laTest[1]
abUnitTest = newobject('abUnitTest', 'abDev.prg')
* {fr} Supprimer la Colonne de gauche
aColDel_Test_a(@m.laTest)
abUnitTest.Test(1, @m.laTest, 1)
abUnitTest.assert(alen(laTest, 2), 3)
abUnitTest.assert(laTest[1,1], 2)
abUnitTest.assert(laTest[2,1], "B")
abUnitTest.assert(laTest[1,2], 3)
abUnitTest.assert(laTest[2,2], "C")
* {fr} Supprimer une Colonne interne
aColDel_Test_a(@m.laTest)
abUnitTest.Test(1, @m.laTest, 2)
abUnitTest.assert(alen(laTest, 2), 3)
abUnitTest.assert(laTest[1,1], 1)
abUnitTest.assert(laTest[2,1], "A")
abUnitTest.assert(laTest[1,2], 3)
abUnitTest.assert(laTest[2,2], "C")
* {fr} Supprimer la Colonne de droite
aColDel_Test_a(@m.laTest)
abUnitTest.Test(1, @m.laTest, 4)
abUnitTest.assert(alen(laTest, 2), 3)
abUnitTest.assert(laTest[1,1], 1)
abUnitTest.assert(laTest[2,1], "A")
abUnitTest.assert(laTest[1,2], 2)
abUnitTest.assert(laTest[2,2], "B")
abUnitTest.assert(laTest[1,3], 3)
abUnitTest.assert(laTest[2,3], "C")
return abUnitTest.Result()
* --------------------------------------
procedure aColDel_Test_a(laTest)
dimension laTest[2,4]
laTest[1,1] = 1
laTest[1,2] = 2
laTest[1,3] = 3
laTest[1,4] = 4
laTest[2,1] = "A"
laTest[2,2] = "B"
laTest[2,3] = "C"
laTest[2,4] = "D"
* --------------------------------------
procedure aColDel_Test_aa(laTest)
local lcTest
text TO lcTest NOSHOW PRETEXT 1+2
11 .T.
21 .F. "toto"
31 .T. "tutu" {^2014-01-10}
41 .NULL. "tutu" {^2014-01-11}
ENDTEXT
return aLinesCols(@m.laTest, m.lcTest, TABUL, 'ILCD')
* ===================================================================
function aColsDel && {fr} Supprime physiquement plusieurs colonnes d'un Tableau {en} remove many columns from an Array
lparameters ;
taResult; && @ {fr} Résultat {en} Result
, tnCol1; && {fr} n° de la première Colonne à supprimer {en} index of the first Column to remove
, tnCol2 && {fr} [dernière] N° de la dernière Colonne à supprimer {en} [last] index of the last Column to remove
external Array taResult
local llResult, lnResult; && {fr} analogue à aDel() : 1 si les colonnes sont bien supprimées, 0 sinon {en} like aDel() if columns succesfull removed 1, otherwise 0
, lnCols, lnCol2, liCol
lnResult = 0
* {fr} Si les paramètres requis sont valides
llResult = not type('taResult[1,2]') == 'U' ; && {fr} au moins 2 colonnes {en} at least two columns
and vartype(m.tnCol1) == 'N' ;
and m.tnCol1 > 0 ;
and m.tnCol1 <= alen(taResult, 2)
assert m.llResult message cAssertMsg(icase(;
cLangUser() = 'fr', 'Paramètre(s) requis incorrect(s)',; && copy-paste this line to add another language support
'Some of the required parameters are invalid'; && Default: English
))
if m.llResult
* {fr} Régler les paramètres optionnels à leur Valeur par défaut
lnCols = alen(taResult, 2)
lnCol2 = iif(vartype(m.tnCol2) == 'N' and m.tnCol2 <= m.lnCols, m.tnCol2, m.lnCols)
lnCol2 = max(m.lnCol2, m.tnCol1)
* {fr} Si la suppression des colonnes est possible
llResult = not (m.tnCol1 = 1 and m.lnCol2 = m.lnCols)
assert m.llResult message cAssertMsg(icase(;
cLangUser() = 'fr', "Impossible de supprimer toutes les colonnes d'un Tableau",; && copy-paste this line to add another language support
'Cannot remove all columns from an Array'; && Default: English
))
if m.llResult
* {fr} Supprimer chaque Colonne
for m.liCol = m.lnCol2 to m.tnCol1 step -1
lnResult = aColDel(@m.taResult, m.liCol)
if m.lnResult = 0
exit
endif
endfor
endif
endif
return m.lnResult
* --------------------------------------
procedure aColsDel_Test
local Array laTest[1]
local abUnitTest as abUnitTest of abDev.prg, laTest[1]
abUnitTest = newobject('abUnitTest', 'abDev.prg')
aColDel_Test_a(@m.laTest)
abUnitTest.Test(1, @m.laTest, 2, 3) && {fr} colonnes 2 et 3 supprimées
abUnitTest.assert(alen(laTest, 2), 2)
abUnitTest.assert(laTest[1,1], 1)
abUnitTest.assert(laTest[2,1], "A")
abUnitTest.assert(laTest[1,2], 4)
abUnitTest.assert(laTest[2,2], "D")
aColDel_Test_a(@m.laTest)
abUnitTest.Test(1, @m.laTest, 3) && {fr} colonnes 3 et 4 supprimées
abUnitTest.assert(alen(laTest, 2), 2)
abUnitTest.assert(laTest[1,1], 1)
abUnitTest.assert(laTest[2,1], "A")
abUnitTest.assert(laTest[1,2], 2)
abUnitTest.assert(laTest[2,2], "B")
return abUnitTest.Result()
* ===================================================================
function aVarType && {fr} Vartypes d'après un Tableau ou une liste délimitée ou non {en} Vartypes from an Array or a list delimited or not
lparameters ;
taResult; && @ {fr} Résultat {en} Result
, tuTypes && @ {fr} (Var)types (Array ou cListe) {en} (Var)types (Array or cListe)
external Array taResult, tuTypes
local llArray, llResult
llResult = aClear(@m.taResult)
assert m.llResult message cAssertMsg(textmerge(icase(;
cLangUser() = 'fr', [paramètre(s) invalides : <<cLitteral(m.taResult)>>, <<cLitteral(m.tuTypes)>>],; && copy-paste this line to add another language support
[parameters invalids : <<cLitteral(m.taResult)>>, <<cLitteral(m.tuTypes)>>]; && Default: English
)))
llArray = type('tuTypes', 1) == 'A'
return icase(;
not m.llResult, 0,;
m.llArray, min(acopy(tuTypes, taResult), 0) + alen(taResult),;
vartype(m.tuTypes) == 'C', iif(;
',' $ m.tuTypes or ';' $ m.tuTypes or TABUL $ m.tuTypes or '|' $ m.tuTypes;
, alines(taResult, upper(m.tuTypes), 1+4, ',', ';', TABUL, '|'),;
aChars(@m.taResult, upper(chrtran(m.tuTypes, space(1), '')))),;
0)
* ===================================================================
function aColsIns && {fr} Insère physiquement une ou plusieurs Colonne(s) dans un Tableau {en} Insert one or many columns inside an Array
lparameters ;
taResult; && @ {fr} Résultat {en} Result
, tnColBef; && {fr} [dernière] n° de Colonne APRÈS laquelle insérer la(es) nouvelle(s) Colonne(s), 0 pour ajouter au début {en} [last] index of Column AFTER we insert the new Column(s), 0 to insert at the beginning
, tnColsIns; && {fr} [1] NOmbre de colonnes à insérer {en} [1] number of Column to insert
, tuVal; && {fr} [.F. ou ueMpty(tutYpes)] Valeur des cellules ajoutées {en} [.F. or ueMpty(tutYpes)] Value of cells to insert
, tuTypes && @ {fr} Types des colonnes (Array ou liste) in 'CDGLNOQTUXYI' {en} Types of Column (Array or list) in 'CDGLNOQTUXYI'
local llResult, lnResult; && {fr} Nombre de colonnes après l'insersion {en} number of columns after insertion
, lnRow, liRow;
, lnCol, liCol
lnResult = 0
* {fr} Si un Tableau a été passé
llResult = type('taResult', 1) == 'A'
assert m.llResult message cAssertMsg(textmerge(icase(;
cLangUser() = 'fr', [Tableau attendu en premier paramètre : <<cLitteral(m.taResult)>> !],; && copy-paste this line to add another language support
[Array expected as the first parameter : <<cLitteral(m.taResult)>> !]; && Default: English
)))
if m.llResult
lnRow = alen(taResult, 1)
lnCol = alen(taResult, 2)
* {fr} Si Tableau à une dim.
if m.lnCol = 0
* {fr} Convertir à 2 dimensions
lnCol = 1
dimension taResult[m.lnRow, m.lnCol]
endif
* {fr} Vérifier la validité du n° de Colonne passé
if vartype(m.tnColBef) == 'N'
llResult = between(m.tnColBef, 0, m.lnCol)
assert m.llResult message cAssertMsg(textmerge(icase(;
cLangUser() = 'fr', "le n° de Colonne <<m.tnColBef>> est hors des limites du Tableau.",; && copy-paste this line to add another language support
"index of Column <<m.tnColBef>> outside the length of Array."; && Default: English
)))
else
tnColBef = m.lnCol && {fr} après la dernière Colonne {en} after the last Column
endif
endif
if m.llResult
tnColsIns = iif(vartype(m.tnColsIns) == 'N' and m.tnColsIns > 0, m.tnColsIns, 1)
lnResult = m.lnCol + m.tnColsIns
* {fr} Créer un Tableau de travail
local laTemp[m.lnRow, m.lnResult];
, laType[1], lnType;
, llColBeg, lnColIns, llColIns, llColInsTyped
* {fr} Voir si le typage est demandé
lnType = aVarType(@m.laType, @m.tuTypes)
* {fr} Remplir le Tableau de travail
for m.liCol = 1 to m.lnResult
llColBeg = m.liCol <= m.tnColBef
lnColIns = m.liCol - m.tnColBef
llColIns = between(m.lnColIns, 1, m.tnColsIns)
llColInsTyped = m.llColIns and m.lnColIns <= m.lnType
for liRow = 1 to m.lnRow
laTemp[m.liRow, m.liCol] = icase(;
m.llColBeg,; && {fr} avant la(es) nouvelle(s) Colonne(s) {en} before new Column(s)
taResult[m.liRow, m.liCol],;
m.llColIns,; && {fr} nouvelle(s) Colonne(s) {en} new Column(s)
iif(m.llColInsTyped;
, uEmpty(laType[m.lnColIns]);
, m.tuVal;
),;
taResult[m.liRow, m.liCol - m.tnColsIns]; && {fr} après la(es) nouvelle(s) Colonne(s) {en} after new Column(s)
)
endfor
endfor
* {fr} Copier le Tableau de travail dans le résultat
dimension taResult[m.lnRow, m.lnResult]
acopy(laTemp, taResult) && {fr} contrairement à ce que dit la doc, ne dimensionne pas correctement taResult
endif
return m.lnResult
endfunc
* --------------------------------------
procedure aColsIns_Test && {fr} Teste aColsIns()
local abUnitTest as abUnitTest of abDev.prg, laTest[1]
abUnitTest = newobject('abUnitTest', 'abDev.prg')
&& {fr} Tableau À UNE DIMENSION
aColsIns_Test_a(@m.laTest, 3)
abUnitTest.Test(3, @m.laTest, 0, 2) && 2 colonnes au début
abUnitTest.assert(.f., laTest[3,1]) && 1ère Colonne insérée
abUnitTest.assert(2, laTest[2,3]) && {fr} La Colonne initiale est maintenant # 3
&& {fr} Tableau À DEUX DIMENSIONS
&& {fr} ajout au début
aColsIns_Test_a(@m.laTest, 2, 3)
abUnitTest.Test(5, @m.laTest, 0, 2) && 2 colonnes au début (1,2)
abUnitTest.assert(6, laTest[2,5]) && {fr} donnée initiale
abUnitTest.assert(.f., laTest[1,2]) && 2ème Colonne insérée
&& {fr} ajout à l'intérieur
aColsIns_Test_a(@m.laTest, 2, 3)
abUnitTest.Test(5, @m.laTest, 2, 2) && 2 colonnes après la 2 (3,4)
abUnitTest.assert(6, laTest[2,5]) && {fr} donnée initiale
abUnitTest.assert(.f., laTest[1,4]) && 2ème Colonne insérée
&& {fr} ajout à la fin
aColsIns_Test_a(@m.laTest, 2, 3)
abUnitTest.Test(5, @m.laTest, , 2) && 2 colonnes à la fin (4,5)
abUnitTest.assert(6, laTest[2,3]) && {fr} donnée initiale
abUnitTest.assert(.f., laTest[2,5]) && 2ème Colonne insérée
&& {fr} ajout à la fin avec Valeur imposée
aColsIns_Test_a(@m.laTest, 2, 3)
abUnitTest.Test(5, @m.laTest, , 2, 'test') && 2 colonnes à la fin (4,5)
abUnitTest.assert(6, laTest[2,3]) && {fr} donnée initiale
abUnitTest.assert('test', laTest[2,5]) && 2ème Colonne insérée
&& {fr} ajout à la fin avec type imposé
aColsIns_Test_a(@m.laTest, 2, 3)
abUnitTest.Test(5, @m.laTest, , 2, , 'IC') && 2 colonnes à la fin (4,5)
abUnitTest.assert(6, laTest[2,3]) && {fr} donnée initiale
abUnitTest.assert('', laTest[2,5]) && 2ème Colonne insérée
* --------------------------------------
procedure aColsIns_Test_a && {fr} Initialise le Tableau de test avec aElement()
lparameters taTest, tnRows, tnCols
external Array taTest
if empty(m.tnCols)
dimension taTest[m.tnRows]
else
dimension taTest[m.tnRows, m.tnCols]
endif
local lnTest
for lnTest = 1 to alen(taTest)
taTest[m.lnTest] = m.lnTest
endfor
* ===================================================================
function laEqual && {fr} Deux tableaux sont identiques {en} Two arrays are equals
lparameters ;
ta1; && @ {fr} Tableau 1 {en} Array 1
, ta2; && @ {fr} Tableau 2 {en} Array 2
, tlCase; && {fr} [.F.] SI élements de type caractère, ignorer la casse, les diacritiques et les espaces de fin {en} IF type 'C', case insensitive and ending spaces are ignored
, taDelta && @ {fr} Tableau différentiel {en} Array of differences
tlCase = lTrue(m.tlCase)
external Array ta1, ta2, taDelta
local llParms, lnElt1, lnElt2, lnCol1, lnCol2, liElt, luElt1, luElt2, llElt;
, lcType, llDelta, lnDelta, liDelta;
, llResult && {fr} Tableaux identiques {en} same arrays
* {fr} Si deux tableaux ont bien été passés
llParms = type('ta1', 1) == 'A' and type('ta2', 1) == 'A'
assert m.llParms message cAssertMsg(textmerge(icase(;
cLangUser() = 'fr', [Deux tableaux attendus: <<ta1>> | <<ta2>>],; && copy-paste this line to add another language support
[Two arrays expected: <<ta1>> | <<ta2>>]; && Default: English
)))
if m.llParms
llDelta = aClear(@m.taDelta)
lnElt1 = alen(ta1)
lnElt2 = alen(ta2)
if m.lnElt1 = m.lnElt2 or m.llDelta
* {fr} Pour chaque élément
lnDelta = 0
lnCol1 = alen(m.ta1, 2)
lnCol2 = alen(m.ta2, 2)
llResult = .t.
for liElt = 1 to max(m.lnElt1, m.lnElt2)
luElt1 = iif(m.liElt <= m.lnElt1, ta1[m.liElt], .null.)
luElt2 = iif(m.liElt <= m.lnElt2, ta2[m.liElt], .null.)
lcType = vartype(m.luElt1)
llElt = m.lcType == vartype(m.luElt2); && {fr} éléments de même type {en} same type element
and iif(m.lcType = 'C' and m.tlCase;
, upper(cEuroAnsi(rtrim(m.luElt1))) == upper(cEuroAnsi(rtrim(m.luElt2)));
, luEqual(m.luElt1, m.luElt2);
)
llResult = m.llResult and m.llElt
if not m.llElt && {fr} élements différents {en} type element not similar
if m.llDelta
lnDelta = m.lnDelta + 1
dimension taDelta[m.lnDelta, Evl(m.lnCol1, 1) + Evl(m.lnCol2, 1)]
liDelta = iif(m.liElt <= m.lnElt1;
, iif(m.lnCol1 > 0, asubscript(m.ta1, m.liElt, 2), 1);
, iif(m.lnCol2 > 0, asubscript(m.ta2, m.liElt, 2), 1);
)
taDelta[m.lnDelta, m.liDelta] = m.luElt1
taDelta[m.lnDelta, Evl(m.lnCol1, 1) + m.liDelta] = m.luElt2
else
exit
endif
endif
endfor
endif
endif
return m.llResult
* -------------------------------------------------------------
procedure laEqual_test
local abUnitTest as abUnitTest of abDev.prg
abUnitTest = newobject('abUnitTest', 'abDev.prg')