-
Notifications
You must be signed in to change notification settings - Fork 28
/
lpeval_wrappers_string.inc
812 lines (657 loc) · 28.7 KB
/
lpeval_wrappers_string.inc
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
{
Author: Niels A.D
Project: Lape (https://github.com/nielsAD/lape)
License: GNU Lesser GPL (http://www.gnu.org/licenses/lgpl.html)
This include contains all the wrappers for string related functions.
}
{%MainUnit lpeval.pas}
procedure _LapeUTF8EncodeW(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PAnsiString(Result)^ := UTF8Encode(PWideString(Params^[0])^);
end;
procedure _LapeUTF8EncodeU(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PAnsiString(Result)^ := UTF8Encode(PUnicodeString(Params^[0])^);
end;
procedure _LapeUTF8DecodeW(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PWideString(Result)^ := UTF8Decode(PAnsiString(Params^[0])^);
end;
procedure _LapeUTF8DecodeU(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PUnicodeString(Result)^ := UTF8Decode(PAnsiString(Params^[0])^);
end;
procedure _LapeUpperCase(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := UpperCase(PlpString(Params^[0])^);
end;
procedure _LapeLowerCase(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := LowerCase(PlpString(Params^[0])^);
end;
procedure _LapeUpCaseA(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PAnsiChar(Result)^ := UpCase(PAnsiChar(Params^[0])^);
end;
procedure _LapeUpCaseW(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PWideChar(Result)^ := UpCase(PWideChar(Params^[0])^);
end;
procedure _LapeCompareStr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := CompareStr(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeCompareText(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := CompareText(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeSameText(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := SameText(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeAnsiUpperCase(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := AnsiUpperCase(PlpString(Params^[0])^);
end;
procedure _LapeAnsiLowerCase(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := AnsiLowerCase(PlpString(Params^[0])^);
end;
procedure _LapeAnsiCompareStr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := AnsiCompareStr(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeAnsiCompareText(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := AnsiCompareText(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeAnsiSameText(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := AnsiSameText(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeAnsiSameStr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := AnsiSameStr(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeWideUpperCase(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PWideString(Result)^ := WideUpperCase(PWideString(Params^[0])^);
end;
procedure _LapeWideLowerCase(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PWideString(Result)^ := WideLowerCase(PWideString(Params^[0])^);
end;
procedure _LapeWideCompareStr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := WideCompareStr(PWideString(Params^[0])^, PWideString(Params^[1])^);
end;
procedure _LapeWideCompareText(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := WideCompareText(PWideString(Params^[0])^, PWideString(Params^[1])^);
end;
procedure _LapeWideSameText(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := WideSameText(PWideString(Params^[0])^, PWideString(Params^[1])^);
end;
procedure _LapeWideSameStr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := WideSameStr(PWideString(Params^[0])^, PWideString(Params^[1])^);
end;
procedure _LapeWideFormat(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
var
ConstArr: TVarRecList;
begin
ConstArr := VariantArrToConstArr(PVariantArray(Params^[1])^);
PWideString(Result)^ := WideFormat(PWideString(Params^[0])^, ConstArr.VarRecs);
end;
procedure _LapeTrim(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := Trim(PlpString(Params^[0])^);
end;
procedure _LapeTrimLeft(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := TrimLeft(PlpString(Params^[0])^);
end;
procedure _LapeTrimRight(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := TrimRight(PlpString(Params^[0])^);
end;
procedure _LapePadL(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := StringOfChar(PlpChar(Params^[2])^, PUInt32(Params^[1])^ - UInt32(Length(PlpString(Params^[0])^))) + PlpString(Params^[0])^;
end;
procedure _LapePadR(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := PlpString(Params^[0])^ + StringOfChar(PlpChar(Params^[2])^, PUInt32(Params^[1])^ - UInt32(Length(PlpString(Params^[0])^)));
end;
procedure _LapeQuotedStr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := QuotedStr(PlpString(Params^[0])^);
end;
procedure _LapeIntToHex(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(IntToHex(PInt64(Params^[0])^, PInt32(Params^[1])^));
end;
procedure _LapeUIntToHex(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(IntToHex(PUInt64(Params^[0])^, PInt32(Params^[1])^));
end;
procedure _LapeStrToInt(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := StrToInt(string(PlpString(Params^[0])^));
end;
procedure _LapeStrToIntDef(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := StrToIntDef(string(PlpString(Params^[0])^), PInt32(Params^[1])^);
end;
procedure _LapeStrToInt64(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt64(Result)^ := StrToInt64(string(PlpString(Params^[0])^));
end;
procedure _LapeStrToInt64Def(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt64(Result)^ := StrToInt64Def(string(PlpString(Params^[0])^), PInt64(Params^[1])^);
end;
procedure _LapeStrToUInt64(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PUInt64(Result)^ := StrToUInt64(string(PlpString(Params^[0])^));
end;
procedure _LapeStrToUInt64Def(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PUInt64(Result)^ := StrToUInt64Def(string(PlpString(Params^[0])^), PUInt64(Params^[1])^);
end;
procedure _LapeStrToFloat(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpFloat(Result)^ := StrToFloat(string(PlpString(Params^[0])^));
end;
procedure _LapeStrToFloatDef(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpFloat(Result)^ := StrToFloatDef(string(PlpString(Params^[0])^), PlpFloat(Params^[1])^);
end;
procedure _LapeStrToCurr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PCurrency(Result)^ := StrToCurr(string(PlpString(Params^[0])^));
end;
procedure _LapeStrToCurrDef(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PCurrency(Result)^ := StrToCurrDef(string(PlpString(Params^[0])^), PCurrency(Params^[1])^);
end;
procedure _LapeStrToBool(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := StrToBool(string(PlpString(Params^[0])^));
end;
procedure _LapeBoolToStr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if PBoolean(Params^[0])^ then
PlpString(Result)^ := PlpString(Params^[1])^
else
PlpString(Result)^ := PlpString(Params^[2])^;
end;
procedure _LapeStrToBoolDef(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := StrToBoolDef(string(PlpString(Params^[0])^), PBoolean(Params^[1])^);
end;
procedure _LapeFormat(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
var
ConstArr: TVarRecList;
begin
ConstArr := VariantArrToConstArr(PVariantArray(Params^[1])^);
PlpString(Result)^ := Format(PlpString(Params^[0])^, ConstArr.VarRecs);
end;
procedure _LapeFormatFloat(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(FormatFloat(string(PlpString(Params^[0])^), PlpFloat(Params^[1])^));
end;
procedure _LapeFormatCurr(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := lpString(FormatCurr(string(PlpString(Params^[0])^), PCurrency(Params^[1])^));
end;
procedure _LapeLastDelimiter(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := LastDelimiter(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeStringReplace(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := StringReplace(PlpString(Params^[0])^, PlpString(Params^[1])^, PlpString(Params^[2])^, TReplaceFlags(PLapeSmallEnum(Params^[3])^));
end;
procedure _LapeWideStringReplace(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PWideString(Result)^ := WideStringReplace(PWideString(Params^[0])^, PWideString(Params^[1])^, PWideString(Params^[2])^, TReplaceFlags(PLapeSmallEnum(Params^[3])^));
end;
procedure _LapeUnicodeStringReplace(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PUnicodeString(Result)^ := {$IFDEF FPC}UnicodeStringReplace{$ELSE}StringReplace{$ENDIF}(PUnicodeString(Params^[0])^, PUnicodeString(Params^[1])^, PUnicodeString(Params^[2])^, TReplaceFlags(PLapeSmallEnum(Params^[3])^));
end;
procedure _LapeIsDelimiter(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := IsDelimiter(PlpString(Params^[0])^, PlpString(Params^[1])^, PSizeInt(Params^[2])^);
end;
procedure _LapePosA(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := Pos(PlpString(Params^[0])^, PlpString(Params^[1])^, PSizeInt(Params^[2])^);
end;
procedure _LapePosW(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := Pos(PWideString(Params^[0])^, PWideString(Params^[1])^, PSizeInt(Params^[2])^);
end;
procedure _LapePosU(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSizeInt(Result)^ := Pos(PUnicodeString(Params^[0])^, PUnicodeString(Params^[1])^, PSizeInt(Params^[2])^);
end;
procedure _LapeStringOfChar(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := StringOfChar(PlpChar(Params^[0])^, PSizeInt(Params^[1])^);
end;
procedure _LapeString_SetLength(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
SetLength(PlpString(Params^[0])^, PInteger(Params^[1])^);
end;
procedure _LapeString_Length(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInteger(Result)^ := Length(PlpString(Params^[0])^);
end;
procedure _LapeString_Low(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInteger(Result)^ := Low(PlpString(Params^[0])^);
end;
procedure _LapeString_High(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInteger(Result)^ := High(PlpString(Params^[0])^);
end;
procedure _LapeString_Pop(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function _Pop(var Str: lpString): Char;
begin
if Length(Str) < 1 then
LapeExceptionFmt(lpeIndexOutOfRange, [Length(Str), Low(Str), Length(Str)]);
Result := Str[Length(Str)];
SetLength(Str, Length(Str) - 1);
end;
begin
PlpChar(Result)^ := _Pop(PlpString(Params^[0])^);
end;
procedure _LapeString_First(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function _First(const Str: lpString): Char;
begin
if Length(Str) < 1 then
LapeExceptionFmt(lpeIndexOutOfRange, [Low(Str), Low(Str), Length(Str)]);
Result := Str[Low(Str)];
end;
begin
PlpChar(Result)^ := _First(PlpString(Params^[0])^);
end;
procedure _LapeString_Last(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function _Last(const Str: lpString): Char;
begin
if Length(Str) < 1 then
LapeExceptionFmt(lpeIndexOutOfRange, [High(Str), Low(Str), Length(Str)]);
Result := Str[High(Str)];
end;
begin
PlpChar(Result)^ := _Last(PlpString(Params^[0])^);
end;
procedure _LapeString_Insert(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Insert(PlpString(Params^[1])^, PlpString(Params^[0])^, PInteger(Params^[2])^);
end;
procedure _LapeString_DeleteIndex(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Delete(PlpString(Params^[0])^, PInteger(Params^[1])^, 1);
end;
procedure _LapeString_DeleteRange(const Params: PParamArray); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
Delete(PlpString(Params^[0])^, PInteger(Params^[1])^, (PInteger(Params^[2])^ - PInteger(Params^[1])^) + 1);
end;
procedure _LapeString_Copy(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := Copy(PlpString(Params^[0])^, 1, Length(PlpString(Params^[0])^));
end;
procedure _LapeString_CopyRange(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := Copy(PlpString(Params^[0])^, PInteger(Params^[1])^, (PInteger(Params^[2])^ - PInteger(Params^[1])^) + 1);
end;
procedure _LapeString_Replace(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := StringReplace(PlpString(Params^[0])^, PlpString(Params^[1])^, PlpString(Params^[2])^, TReplaceFlags(Params^[3]^));
end;
procedure _LapeString_ToUpper(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := UpperCase(PlpString(Params^[0])^);
end;
procedure _LapeString_ToLower(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := LowerCase(PlpString(Params^[0])^);
end;
procedure _LapeString_IndexOf(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := Pos(PlpString(Params^[1])^, PlpString(Params^[0])^, PInt32(Params^[2])^);
end;
procedure _LapeString_LastIndexOf(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function _LastIndexOf(const Self, AValue: lpString; Offset: SizeInt): SizeInt;
var
i, StartIndex: SizeInt;
begin
if (Length(Self) > 0) and (Length(AValue) > 0) then
begin
StartIndex := (Length(Self) - Length(AValue) + 1) - (Offset - 1);
if (StartIndex > Length(Self)) then
StartIndex := Length(Self);
for i := StartIndex downto 1 do
if CompareMem(@Self[i], @AValue[1], Length(AValue) * SizeOf(lpChar)) then
Exit(i);
end;
Result := -1;
end;
begin
PInt32(Result)^ := _LastIndexOf(PlpString(Params^[0])^, PlpString(Params^[1])^, PInt32(Params^[2])^);
end;
procedure _LapeString_Trim(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := Trim(PlpString(Params^[0])^);
end;
procedure _LapeString_TrimLeft(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := TrimLeft(PlpString(Params^[0])^);
end;
procedure _LapeString_TrimRight(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := TrimRight(PlpString(Params^[0])^);
end;
procedure _LapeString_Split(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
type
lpStringArray = array of lpString;
function _Split(const Str, Seperator: lpString; ExcludeEmpty: Boolean): lpStringArray;
var
StrLen, SepLen, MaxLen, ResultCount: SizeInt;
procedure Add(const Index, Count: Integer);
begin
if ExcludeEmpty and (Count = 0) then
Exit;
if (ResultCount >= Length(Result)) then
SetLength(Result, 4 + (Length(Result) * 2));
Result[ResultCount] := System.Copy(Str, Index, Count);
Inc(ResultCount);
end;
function NextSep(const StartIndex: SizeInt): SizeInt;
var
I: SizeInt;
Ptr: PlpChar;
begin
if (StartIndex <= StrLen) then
begin
Ptr := @Str[StartIndex];
I := StartIndex - 1;
while (I <= MaxLen) do
begin
Inc(I);
if (PlpChar(Seperator)^ = Ptr^) and CompareMem(Ptr, PlpChar(Seperator), SepLen * SizeOf(lpChar)) then
Exit(I);
Inc(Ptr);
end;
end;
Result := -1;
end;
var
FoundSep, LastSep: SizeInt;
begin
if (Length(Seperator) = 0) then
Result := [Str]
else
begin
Result := [];
ResultCount := 0;
StrLen := Length(Str);
SepLen := Length(Seperator);
MaxLen := StrLen - SepLen;
LastSep := 1;
FoundSep := NextSep(1);
while (FoundSep > 0) do
begin
Add(LastSep, FoundSep - LastSep);
LastSep := FoundSep + SepLen;
FoundSep := NextSep(LastSep);
end;
if (LastSep <= StrLen) then
Add(LastSep, MaxInt);
SetLength(Result, ResultCount);
end;
end;
begin
lpStringArray(Result^) := _Split(PlpString(Params^[0])^, PlpString(Params^[1])^, PBoolean(Params^[2])^);
end;
procedure _LapeString_Contains(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if PBoolean(Params^[2])^ then
PBoolean(Result)^ := Pos(PlpString(Params^[1])^, PlpString(Params^[0])^) > 0
else
PBoolean(Result)^ := Pos(LowerCase(PlpString(Params^[1])^), LowerCase(PlpString(Params^[0])^)) > 0;
end;
procedure _LapeString_Count(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function _Count(Str, SubStr: lpString; CaseSens: Boolean): Integer;
var
Offset, Index: SizeInt;
begin
Result := 0;
if not CaseSens then
begin
Str := LowerCase(Str);
SubStr := LowerCase(SubStr);
end;
Offset := 1;
repeat
Index := Pos(SubStr, Str, Offset);
Offset := Index + Length(SubStr);
if (Index > 0) then
Inc(Result);
until (Index < 1);
end;
begin
PInteger(Result)^ := _Count(PlpString(Params^[0])^, PlpString(Params^[1])^, PBoolean(Params^[2])^);
end;
procedure _LapeString_Equals(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
if PBoolean(Params^[2])^ then
PBoolean(Result)^ := {$IF DEFINED(LAPE_UNICODE) and DECLARED(UnicodeSameStr)}UnicodeSameStr{$ELSE}SameStr{$ENDIF}(PlpString(Params^[1])^, PlpString(Params^[0])^)
else
PBoolean(Result)^ := {$IF DEFINED(LAPE_UNICODE) and DECLARED(UnicodeSameText)}UnicodeSameText{$ELSE}SameText{$ENDIF}(PlpString(Params^[1])^, PlpString(Params^[0])^);
end;
procedure _LapeString_Compare(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := {$IF DEFINED(LAPE_UNICODE) and DECLARED(UnicodeCompareText)}UnicodeCompareText{$ELSE}CompareText{$ENDIF}(PlpString(Params^[0])^, PlpString(Params^[1])^);
end;
procedure _LapeString_PadLeft(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := StringOfChar(PlpChar(Params^[2])^, PInt32(Params^[1])^ - Int32(Length(PlpString(Params^[0])^))) + PlpString(Params^[0])^;
end;
procedure _LapeString_PadRight(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PlpString(Result)^ := PlpString(Params^[0])^ + StringOfChar(PlpChar(Params^[2])^, PInt32(Params^[1])^ - Int32(Length(PlpString(Params^[0])^)));
end;
procedure _LapeString_StartsWith(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function StartsWith(const Self, Value: String; CaseSenstive: Boolean): Boolean;
begin
case CaseSenstive of
False: Result := (Length(Value) > 0) and SameText(System.Copy(Self, 1, Length(Value)), Value);
True: Result := (Length(Value) > 0) and (System.Copy(Self, 1, Length(Value)) = Value);
end;
end;
begin
PBoolean(Result)^ := StartsWith(PlpString(Params^[0])^, PlpString(Params^[1])^, PBoolean(Params^[2])^);
end;
procedure _LapeString_EndsWith(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function EndsWith(const Self, Value: String; CaseSenstive: Boolean): Boolean;
begin
case CaseSenstive of
False: Result := (Length(Value) > 0) and SameText(System.Copy(Self, Length(Self) - Length(Value) + 1), Value);
True: Result := (Length(Value) > 0) and (System.Copy(Self, Length(Self) - Length(Value) + 1) = Value);
end;
end;
begin
PBoolean(Result)^ := EndsWith(PlpString(Params^[0])^, PlpString(Params^[1])^, PBoolean(Params^[2])^);
end;
procedure _LapeString_ToBoolean(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := StrToBool(PlpString(Params^[0])^);
end;
procedure _LapeString_ToBooleanDef(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := StrToBoolDef(PlpString(Params^[0])^, PBoolean(Params^[1])^);
end;
procedure _LapeString_ToInt32(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := StrToInt(PlpString(Params^[0])^);
end;
procedure _LapeString_ToInt32Def(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt32(Result)^ := StrToIntDef(PlpString(Params^[0])^, PInt32(Params^[1])^);
end;
procedure _LapeString_ToInt64(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt64(Result)^ := StrToInt64(PlpString(Params^[0])^);
end;
procedure _LapeString_ToInt64Def(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PInt64(Result)^ := StrToInt64Def(PlpString(Params^[0])^, PInt64(Params^[1])^);
end;
procedure _LapeString_ToSingle(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSingle(Result)^ := StrToFloatDot(PlpString(Params^[0])^);
end;
procedure _LapeString_ToSingleDef(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PSingle(Result)^ := StrToFloatDotDef(PlpString(Params^[0])^, PSingle(Params^[1])^);
end;
procedure _LapeString_ToDouble(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PDouble(Result)^ := StrToFloatDot(PlpString(Params^[0])^);
end;
procedure _LapeString_ToDoubleDef(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PDouble(Result)^ := StrToFloatDotDef(PlpString(Params^[0])^, PDouble(Params^[1])^);
end;
procedure _LapeString_ToExtended(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PExtended(Result)^ := StrToFloatDot(PlpString(Params^[0])^);
end;
procedure _LapeString_ToExtendedDef(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PExtended(Result)^ := StrToFloatDotDef(PlpString(Params^[0])^, PExtended(Params^[1])^);
end;
procedure _LapeString_IsUpper(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function IsUpper(const S: lpString): Boolean;
var
I: Integer;
begin
for I := 1 to Length(S) do
if not CharInSet(S[I], ['A'..'Z']) then
Exit(False);
Result := S <> '';
end;
begin
PBoolean(Result)^ := IsUpper(PlpString(Params^[0])^);
end;
procedure _LapeString_IsLower(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function IsLower(const S: lpString): Boolean;
var
I: Integer;
begin
for I := 1 to Length(S) do
if (not CharInSet(S[I], ['a'..'z'])) then
Exit(False);
Result := S <> '';
end;
begin
PBoolean(Result)^ := IsLower(PlpString(Params^[0])^);
end;
procedure _LapeString_IsAlpha(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function IsAlpha(const S: lpString): Boolean;
var
I: Integer;
begin
for I := 1 to Length(S) do
if (not CharInSet(S[I], ['a'..'z', 'A'..'Z'])) then
Exit(False);
Result := S <> '';
end;
begin
PBoolean(Result)^ := IsAlpha(PlpString(Params^[0])^);
end;
procedure _LapeString_IsAlphaNum(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function IsAlphaNum(const S: lpString): Boolean;
var
I: Integer;
begin
for I := 1 to Length(S) do
if (not CharInSet(S[I], ['0'..'9', 'a'..'z', 'A'..'Z'])) then
Exit(False);
Result := S <> '';
end;
begin
PBoolean(Result)^ := IsAlphaNum(PlpString(Params^[0])^);
end;
procedure _LapeString_IsNumeric(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function IsNumeric(const S: lpString): Boolean;
var
I: Integer;
begin
for I := 1 to Length(S) do
if (not CharInSet(S[I], ['0'..'9'])) then
Exit(False);
Result := S <> '';
end;
begin
PBoolean(Result)^ := IsNumeric(PlpString(Params^[0])^);
end;
procedure _LapeString_IsFloat(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
var
_: Single;
begin
PBoolean(Result)^ := TryStrToFloat(PlpString(Params^[0])^, _);
end;
procedure _LapeString_IsInteger(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
var
_: Int64;
begin
PBoolean(Result)^ := TryStrToInt64(PlpString(Params^[0])^, _) or TryStrToUInt64(PlpString(Params^[0])^, UInt64(_));
end;
procedure _LapeChar_ToUpper(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function _ToUpper(const C: lpChar): lpChar;
begin
if (C in ['a'..'z']) then
Result := lpChar(Ord(C) - 32)
else
Result := C;
end;
begin
PlpChar(Result)^ := _ToUpper(PlpChar(Params^[0])^);
end;
procedure _LapeChar_ToLower(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
function _ToLower(const C: lpChar): lpChar;
begin
if CharInSet(C, ['A'..'Z']) then
Result := lpChar(Ord(C) + 32)
else
Result := C;
end;
begin
PlpChar(Result)^ := _ToLower(PlpChar(Params^[0])^);
end;
procedure _LapeChar_IsUpper(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := CharInSet(PlpChar(Params^[0])^, ['A'..'Z']);
end;
procedure _LapeChar_IsLower(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := CharInSet(PlpChar(Params^[0])^, ['a'..'z']);
end;
procedure _LapeChar_IsAlpha(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := CharInSet(PlpChar(Params^[0])^, ['a'..'z', 'A'..'Z']);
end;
procedure _LapeChar_IsAlphaNum(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := CharInSet(PlpChar(Params^[0])^, ['0'..'9', 'a'..'z', 'A'..'Z']);
end;
procedure _LapeChar_IsNumeric(const Params: PParamArray; const Result: Pointer); {$IFDEF Lape_CDECL}cdecl;{$ENDIF}
begin
PBoolean(Result)^ := CharInSet(PlpChar(Params^[0])^, ['0'..'9']);
end;