-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFormatting.pas
749 lines (689 loc) · 26.1 KB
/
Formatting.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
{
Copyright (c) Peter Karpov 2010 - 2018.
Usage of the works is permitted provided that this instrument is retained with
the works, so that any entity that uses the works is notified of this instrument.
DISCLAIMER: THE WORKS ARE WITHOUT WARRANTY.
}
{$IFDEF FPC} {$MODE DELPHI} {$ENDIF}
unit Formatting; ////////////////////////////////////////////////////////////////////
{
>> Version: 0.4
>> Description
Original string formatting function. Part of InvLibs unit collection.
>> Author
Peter Karpov
Email : [email protected]
Homepage : inversed.ru
GitHub : inversed-ru
Twitter : @inversed_ru
>> Usage
Format function takes a format string and a list of arguments as input. The format
string consists of any characters mixed with the format specifiers contained in
curly braces, which are double-escapable. A specifier consists of multiple fields.
If a field is not present, the default value is used.
1. Alignment
< Left
<= Left with truncation
> Right (default)
=> Right with truncation
^ Center
^=, =^ Center with truncation
<> Sign left-aligned, number right-aligned
2. Sign
- Sign only for negative numbers (default)
+ Sign for both negative and positive numbers
space Fill character instead of sign for positive numbers
3. Fill character
nothing Pad with spaces (default)
0 Left-pad with zeroes, right-pad with spaces
other Custom fill character, must be different from precision and type
flags
4. Width
5. Precision
: Number of signs after decimal point,
~ Total number of significant digits
6. Type
nothing Acts as 'f' with ':' precision flag, and as 'e' with '~'
f Fixed decimal point
eX Scientific format. 'e' is lowercase and always followed by sign. X
determines the number of digits in the exponent (4 by default).
Alignment is the same as for the number itself, and '0' is used as
a fill character.
(X) Appends SI (metric) prefix after an appropriately scaled number. X
specifies the units of measurement appended after the prefix.
% Multiply by 100, add '%' symbol
tX Thousands separated by symbol X. Single quotes are used if X is not
specified.
>> Design decisions
SysUtils already contains Format function but it was deemed unsatisfactory because
of its limited options. A few existing syntaxes of formatting were considered: C,
C#, Python. C syntax of printf's format tags is rather poor: symmetric things have
assymetric meanings. '-' means left alignment, while '+' means always preceding
result with sign - seriously, what kind of logic is that? C# syntax is better, but
may be cumbersome because of use of placeholders for digits and integer numbers
for alignment. New Python syntax appears to be best of the three, so a few things
were directly taken from it. Overall, proposed syntax was designed to be logical
and easy to use, and flags were selected to be easily readable and memorable.
>> References
1. printf - C++ Reference
http://www.cplusplus.com/reference/clibrary/cstdio/printf/
2. String Formatting in C#
http://blog.stevex.net/string-formatting-in-csharp/
3. PEP 3101 - Advanced String Formatting
http://www.python.org/dev/peps/pep-3101/
>> ToDo
- Handle +-infinity correctly
- Add escape sequences like \t, \n
- Add format-and-write procedure (FWrite, FmtWrite, ...?)
- Get rid of StrUtils, Math, SysUtils dependencies
>> Changelog
0.4 : 2018.09.20 ~ FreePascal compatibility
~ StringUtils 1.13 compatibility
0.3 : 2014.03.09 * Incorrect placement of thousands separators
0.2.1 : 2011.10.14 ~ Moved to generic types
0.2 : 2011.08.07 ~ Split from StringUtils
0.1 : 2011.05.15 + Boolean type support
* Sign formating
0.0 : 2011.03.16 + Initial version
Notation: + added, - removed, * fixed, ~ changed
}
interface ///////////////////////////////////////////////////////////////////////////
// Convert Args to strings according to the format specifiers in the format
// string S and insert them into the corresponding positions in S
function Format(
const S : AnsiString;
const Args : array of const
) : AnsiString;
implementation //////////////////////////////////////////////////////////////////////
uses
SysUtils, // IntToStr, FloatToStrF
invSys,
Math, // Ceil, Sign, Log10
StringUtils;
{-----------------------<< Formatting >>--------------------------------------------}
// Given number of significant digits, returns corresponding number of digits after
// decimal point.
function SignifToFrac(
X : Extended;
SignifDigits : Integer;
NonNegative : Boolean // Return 0 instead of negative results
) : Integer;
var
DigitsBefore : Integer;
Lg : Extended;
begin
X := Abs(X);
// In FPC x64, Extended aliases to Double and MinExtended constant does not exist
if X < MinDouble then
DigitsBefore := 0
else
begin
Lg := Log10(X);
DigitsBefore := Trunc(Lg);
if Lg >= 0 then
Inc(DigitsBefore);
end;
Result := SignifDigits - DigitsBefore;
if NonNegative and (Result < 0) then
Result := 0;
end;
// Format a number with SI (metric) prefixes. SignifDigits specifies what Precision
// means: number of significant digits (True) or digits after the decimal point
// (False).
function FormatSI(
X : Extended;
const Units : AnsiString;
Precision : Integer;
SignifDigits : Boolean;
Spacer : AnsiChar = ' '
) : AnsiString;
type
TSIPrefix =
record
Multiplier : Real;
ShortName : AnsiString;
end;
const
MaxPrefix = 8;
MinPrefix = - 8;
Prefixes : array [MinPrefix .. MaxPrefix] of TSIPrefix =
( (Multiplier: 1e-24; ShortName: 'y'),
(Multiplier: 1e-21; ShortName: 'z'),
(Multiplier: 1e-18; ShortName: 'a'),
(Multiplier: 1e-15; ShortName: 'f'),
(Multiplier: 1e-12; ShortName: 'p'),
(Multiplier: 1e-09; ShortName: 'n'),
(Multiplier: 1e-06; ShortName: 'u'),
(Multiplier: 1e-03; ShortName: 'm'),
(Multiplier: 1 ; ShortName: ' '),
(Multiplier: 1e+03; ShortName: 'k'),
(Multiplier: 1e+06; ShortName: 'M'),
(Multiplier: 1e+09; ShortName: 'G'),
(Multiplier: 1e+12; ShortName: 'T'),
(Multiplier: 1e+15; ShortName: 'P'),
(Multiplier: 1e+18; ShortName: 'E'),
(Multiplier: 1e+21; ShortName: 'Z'),
(Multiplier: 1e+24; ShortName: 'Y') );
var
i : Integer;
DigitsAfter : Integer;
AbsX : Extended;
begin
// Find the prefix
i := MaxPrefix;
AbsX := Abs(X);
while (AbsX <= Prefixes[i].Multiplier) and (i > MinPrefix) do
Dec(i);
// Format according to the prefix
X := X / Prefixes[i].Multiplier;
if SignifDigits then
DigitsAfter := SignifToFrac(X, Precision, {NonNegative:} True)
else
DigitsAfter := Precision;
Result :=
FloatToStrF(X, ffFixed, {Precision:} High(Integer), DigitsAfter) +
Spacer + Prefixes[i].ShortName + Units;
end;
// Convert Args to strings according to the format specifiers in the format
// string S and insert them into the corresponding positions in S
function Format(
const S : AnsiString;
const Args : array of const
) : AnsiString;
type
TAlign = (alLeft, alRight, alCenter, alLeftRight);
TSign = (signNegative, signAllways, signSpace);
TSpecifier =
(spNone, spFixed, spExp, spPercent, spSI, spThousands);
TPrecisionType = (prNone, prSignif, prFrac);
TFormatOptions =
record
Align : TAlign;
Truncate : Boolean;
Sign : TSign;
FillChar,
LeftFillChar,
ThousandsChar : AnsiChar;
Width,
ExpWidth,
Precision : Integer;
PrecisionType : TPrecisionType;
Specifier : TSpecifier;
Units : AnsiString;
end;
const
NotSpecified = -1;
// Get options from the format specifier
procedure GetFormatOptions(
var Options : TFormatOptions;
const FormatStr : AnsiString);
var
Index,
IndexClose : Integer;
Flag : AnsiString;
const
FlagAlighLeft = '<';
FlagAlighRight = '>';
FlagAlighTruncLeft = '<=';
FlagAlighTruncRight = '=>';
FlagAlighLeftRight = '<>';
FlagAlighCen = '^';
FlagAlighTruncCen1 = '^=';
FlagAlighTruncCen2 = '=^';
FlagSignAllways = '+';
FlagSignNegative = '-';
FlagSignSpace = ' ';
FlagZeroPad = '0';
FlagFrac = ':';
FlagSignif = '~';
FlagFixed = 'f';
FlagExp = 'e';
FlagThousands = 't';
FlagPercent = '%';
OpenDim = '(';
CloseDim = ')';
NotFill =
[FlagFrac, FlagSignif, FlagExp, FlagThousands, FlagPercent,
OpenDim, CloseDim];
DefaultThousandsChar = '''';
MaxPrecision = 20 {significant digits};
DefaultExpWidth = 4;
// Get a flag from S at position Index. Flags are checked sequentially. If a
// match is found, Index is incremented by Length(Found).
procedure GetField(
var Found : AnsiString;
var Index : Integer;
const S : AnsiString;
const Flags : array of AnsiString);
var
i : Integer;
begin
Found := '';
for i := Low(Flags) to High(Flags) do
if SubstrAtPos(S, Flags[i], Index) then
begin
Found := Flags[i];
Index := Index + Length(Found);
break;
end;
end;
// Get a character from S at position Index, increment Index.
// Do nothing if Index > Length(S).
procedure GetChar(
var Character : AnsiChar;
var Index : Integer;
const S : AnsiString);
begin
if Index <= Length(S) then
begin
Character := S[Index];
Inc(Index);
end;
end;
// Get a number from S at position Index, increment Index past the number.
// Index is not modified and Default is returned if no number is found.
procedure GetNumber(
var Size : Integer;
var Index : Integer;
const S : AnsiString;
Default : Integer = NotSpecified);
var
TempS : AnsiString;
Len : Integer;
Error : Integer;
begin
TempS := '';
Len := Length(S);
while (Index <= Len) and (S[Index] in Numerals) do
begin
TempS := TempS + S[Index];
Inc(Index);
end;
Val(TempS, Size, Error);
if Error <> 0 then
Size := Default;
end;
begin
with Options do
begin
// Alignment, truncation
Index := 1;
Align := alRight;
Truncate := False;
GetField(
Flag, Index, FormatStr,
[FlagAlighTruncLeft,
FlagAlighTruncRight,
FlagAlighLeftRight,
FlagAlighLeft,
FlagAlighRight,
FlagAlighTruncCen1,
FlagAlighTruncCen2,
FlagAlighCen]);
if (Flag = FlagAlighLeft ) or (Flag = FlagAlighTruncLeft ) then
Align := alLeft
else if (Flag = FlagAlighRight) or (Flag = FlagAlighTruncRight) then
Align := alRight
else if Flag = FlagAlighLeftRight then
Align := alLeftRight
else if (Flag = FlagAlighCen) or
(Flag = FlagAlighTruncCen1) or
(Flag = FlagAlighTruncCen2) then
Align := alCenter;
if (Flag = FlagAlighTruncLeft) or (Flag = FlagAlighTruncRight) or
(Flag = FlagAlighTruncCen1) or (Flag = FlagAlighTruncCen2) then
Truncate := True;
// Sign
Sign := signNegative;
GetField(
Flag, Index, FormatStr,
[FlagSignNegative, FlagSignAllways, FlagSignSpace]);
if Flag = FlagSignAllways then
Sign := signAllways
else if Flag = FlagSignSpace then
Sign := signSpace;
// Padding
FillChar := ' ';
LeftFillChar := ' ';
if ( Index <= Length(FormatStr) ) and
not ( FormatStr[Index] in (Numerals - [FlagZeroPad]) ) and
not ( FormatStr[Index] in NotFill ) then
begin
GetChar(FillChar, Index, FormatStr);
LeftFillChar := FillChar;
if FillChar = FlagZeroPad then
FillChar := ' ';
end;
// Width, precision
GetNumber(Width, Index, FormatStr, {Default:} 0);
GetField(Flag, Index, FormatStr, [FlagFrac, FlagSignif]);
if Flag = FlagFrac then
PrecisionType := prFrac
else if Flag = FlagSignif then
PrecisionType := prSignif
else
PrecisionType := prNone;
GetNumber(Precision, Index, FormatStr);
// Specifier
Specifier := spNone;
ThousandsChar := DefaultThousandsChar;
ExpWidth := DefaultExpWidth;
GetField(
Flag, Index, FormatStr,
[FlagFixed, FlagExp, FlagThousands, FlagPercent, OpenDim]);
if Flag = '' then
case PrecisionType of
prFrac : Specifier := spFixed;
prSignif : Specifier := spExp;
end
else if Flag = FlagFixed then
Specifier := spFixed
else if Flag = FlagExp then
begin
Specifier := spExp;
GetNumber(ExpWidth, Index, FormatStr, DefaultExpWidth);
end
else if Flag = OpenDim then
begin
Specifier := spSI;
if GetPos(IndexClose, FormatStr, CloseDim, {Start:} Index) = Success then
Units := CopyRange(FormatStr, Index, IndexClose - 1)
else
Units := '';
end
else if Flag = FlagThousands then
begin
Specifier := spThousands;
GetChar(ThousandsChar, Index, FormatStr);
end
else if Flag = FlagPercent then
Specifier := spPercent;
end;
end;
// Format the sign of Arg according to Options
function FormatSign(
Arg : Integer;
const Options : TFormatOptions
) : AnsiString;
begin
if Arg < 0 then
Result := '-'
else
case Options.Sign of
signNegative: Result := '';
signAllways : Result := '+';
signSpace : Result := Options.FillChar;
else
Assert(False, 'Unknown sign flag');
end;
end;
// Calculate the spacing for alignment
procedure CalcSpacing(
var LeftGap,
MidGap,
RightGap : Integer;
Figure,
Sign : AnsiString;
const Options : TFormatOptions);
var
SpaceAvail : Integer;
begin
LeftGap := 0;
MidGap := 0;
RightGap := 0;
SpaceAvail := Options.Width - Length(Sign) - Length(Figure);
if SpaceAvail > 0 then
case Options.Align of
alLeft:
RightGap := SpaceAvail;
alRight:
LeftGap := SpaceAvail;
alLeftRight:
MidGap := SpaceAvail;
alCenter:
begin
LeftGap := SpaceAvail div 2;
RightGap := SpaceAvail - LeftGap;
end;
else
Assert(False, 'Unknown alignment type');
end;
end;
// Format a number with specified sign according to Options
function FormatNumber(
Number : AnsiString;
const Sign : AnsiString;
const Options : TFormatOptions
) : AnsiString;
var
LeftFill,
MidFill,
RightFill : AnsiString;
LeftGap,
MidGap,
RightGap,
i : Integer;
const
DecimalDot = '.';
begin
// Get rid of the sign if already present
if Number[1] = '-' then
Number := SuffixFrom(Number, 2);
// Thousands separator
if Options.Specifier = spThousands then
begin
if GetPos(i, Number, DecimalDot) = Fail then
i := Length(Number) + 1;
Dec(i);
while True do
begin
Dec(i, 3);
if i < 1 then
{<---}break
else
Insert(Number, i, Options.ThousandsChar);
end;
end;
// Calculate the spacing, fill
CalcSpacing(LeftGap, MidGap, RightGap, Number, Sign, Options);
LeftFill := DupeString(Options.LeftFillChar, LeftGap);
MidFill := DupeString(Options.LeftFillChar, MidGap);
RightFill := DupeString(Options. FillChar, RightGap);
Result := LeftFill + Sign + MidFill + Number + RightFill;
end;
// Format a real number according to Options
function FormatReal(
Arg : Extended;
var Options : TFormatOptions
) : AnsiString;
var
Number,
ExpPart : AnsiString;
Precision,
Digits : Integer;
ExpIndex : Integer;
const
ExpChar = 'e';
MaxPrecision = 20;
begin
// Set default values if precision is not specified
with Options do
if Precision = NotSpecified then
begin
PrecisionType := prSignif;
Precision := MaxPrecision;
Specifier := spExp;
end;
// Preprocess argument
if Options.Specifier = spPercent then
Arg := 100 * Arg;
case Options.Specifier of
spNone, spFixed, spPercent, spThousands:
begin
// Transform to string
// after calculating number of digits after decimal point
if Options.PrecisionType = prSignif then
Digits := SignifToFrac(Arg, Options.Precision, {NonNegative:} True)
else
Digits := Options.Precision;
Number := FloatToStrF(
Arg, ffFixed, {Precision:} High(Integer), Digits);
end;
spExp:
begin
// Transform to string
// after calculating number of digits before the exponent
Precision := Options.Precision;
if Options.PrecisionType = prFrac then
Inc(Precision);
Number := LowerCase(
FloatToStrF(
Arg, ffExponent, Precision, {Digits:} 1
)
);
// Process the exponent part
if GetPos(ExpIndex, Number, ExpChar) = Success then with Options do
begin
ExpPart := SuffixFrom(Number, ExpIndex + 2);
if Options.Align in [alLeft, alCenter] then
ExpPart := PadRight(ExpPart, FillChar, ExpWidth)
else
ExpPart := PadLeft (ExpPart, '0', ExpWidth);
Number := Prefix(Number, ExpIndex + 1) + ExpPart;
end
else
Assert(False, 'Exp part not found');
end;
spSI:
with Options do
Number := FormatSI(
Arg, Units, Precision, PrecisionType = prSignif, FillChar);
else
Assert(False, 'Unexpected specifier');
end;
// Postprocess, format
if Options.Specifier = spPercent then
Number := Number + '%';
Result := FormatNumber(Number, FormatSign(Sign(Arg), Options), Options);
end;
// Format integer number according to Options
function FormatInt(
Arg : Integer;
var Options : TFormatOptions
) : AnsiString;
begin
if Options.Specifier in [spFixed, spExp, spSI, spPercent] then
Result := FormatReal(Arg, Options)
else
Result := FormatNumber(IntToStr(Arg), FormatSign(Arg, Options), Options);
end;
// Format string according to Options
function FormatString(
const Arg : AnsiString;
const Options : TFormatOptions
) : AnsiString;
var
LeftFill,
RightFill : AnsiString;
LeftGap,
MidGap,
RightGap,
Delta : Integer;
begin
// Calculate spacing, fill
CalcSpacing(LeftGap, MidGap, RightGap, Arg, {Sign:} '', Options);
LeftGap := LeftGap + MidGap;
LeftFill := DupeString(Options.FillChar, LeftGap);
RightFill := DupeString(Options.FillChar, RightGap);
Result := LeftFill + Arg + RightFill;
// Truncate
if Options.Truncate then
case Options.Align of
alLeft:
Result := Prefix(Result, Options.Width);
alRight, alLeftRight:
Result := Suffix(Result, Options.Width);
alCenter:
begin
Delta := Length(Result) - Options.Width;
if Delta > 0 then
Result := Copy(Result, 1 + Delta div 2, Options.Width);
end;
else
Assert(False, 'Unknown alignment');
end;
end;
const
OpenArg = '{';
CloseArg = '}';
OpenX2 = OpenArg + OpenArg;
CloseX2 = CloseArg + CloseArg;
BoolName : array [Boolean] of AnsiString = ('False', 'True');
var
iArg : Integer;
OpenIndex,
CloseIndex,
PrevIndex,
NextBracket : Integer;
FormattedArg : AnsiString;
ArgOptions : TFormatOptions;
FoundOpen,
FoundClose : Boolean;
begin
PrevIndex := 1;
Result := '';
iArg := Low(Args);
repeat
// Find position of next brace
FoundOpen := GetPos( OpenIndex, S, OpenArg, {Start:} PrevIndex) = Success;
FoundClose := GetPos(CloseIndex, S, CloseArg, {Start:} PrevIndex) = Success;
if FoundOpen and FoundClose then
NextBracket := Min(OpenIndex, CloseIndex)
else
NextBracket := Max(OpenIndex, CloseIndex);
// No brace found, exit
if not (FoundOpen or FoundClose) then
break
// Double-escaped braces
else if SubstrAtPos(S, OpenX2, NextBracket) or
SubstrAtPos(S, CloseX2, NextBracket) then
begin
Result := Result + CopyRange(S, PrevIndex, NextBracket);
PrevIndex := NextBracket + 2;
end
// Single closing brace, copy as is
else if SubstrAtPos(S, CloseArg, NextBracket) then
begin
Result := Result + CopyRange(S, PrevIndex, NextBracket);
PrevIndex := NextBracket + 1;
end
// Single opening brace, format
else if SubstrAtPos(S, OpenArg, NextBracket) then
begin
GetFormatOptions( ArgOptions, CopyRange(S, OpenIndex + 1, CloseIndex - 1) );
case Args[iArg].VType of
vtInteger:
FormattedArg := FormatInt (Args[iArg].VInteger, ArgOptions);
vtExtended:
FormattedArg := FormatReal (Args[iArg].VExtended^, ArgOptions);
vtString:
FormattedArg := FormatString(Args[iArg].VString^, ArgOptions);
vtAnsiString:
FormattedArg := FormatString(
AnsiString(Args[iArg].VAnsiString), ArgOptions);
vtChar:
FormattedArg := FormatString(Args[iArg].VChar, ArgOptions);
vtBoolean:
FormattedArg := FormatString(
BoolName[Args[iArg].VBoolean], ArgOptions);
else
Assert(False, 'Unexpected type');
end;
Result := Result + CopyRange(S, PrevIndex, OpenIndex - 1) + FormattedArg;
PrevIndex := CloseIndex + 1;
Inc(iArg);
end;
until ( iArg > High(Args) );
Result := Result + CopyRange( S, PrevIndex, Length(S) );
end;
end.