@@ -226,10 +226,19 @@ function StrSplit(const Str: UnicodeString; const Delim: UnicodeString;
226
226
227
227
// / <summary>Word wraps text Str to form lines of maximum length MaxLen and
228
228
// / offsets each line using spaces to form a left margin of size given by
229
- // / Margin.</summary>
230
- // / <remarks>Output lines are separated by CRLF.</remarks>
231
- function StrWrap (const Str: UnicodeString; const MaxLen, Margin: UInt16):
232
- UnicodeString; overload;
229
+ // / Margin. The first line is offset from the margin by FirstLineOffset spaces.
230
+ // / </summary>
231
+ // / <remarks>
232
+ // / <para>FirstLineOffset offsets to the left of Margin if -ve and to the right
233
+ // / of Margin if +ve.</para>
234
+ // / <para>If FirstLineOffset is -ve then Abs(FirstLineOffset) must be less than
235
+ // / or equal to Margin.</para>
236
+ // / <para>If FirstLineOffset is +ve then FirstLineOffset + Margin must fit in
237
+ // / a UInt16.</para>
238
+ // / <para>Output lines are separated by CRLF.</para>
239
+ // / </remarks>
240
+ function StrWrap (const Str: UnicodeString; const MaxLen, Margin: UInt16;
241
+ const FirstLineOffset: Int16 = 0 ): UnicodeString; overload;
233
242
234
243
// / <summary>Word wraps each paragraph of text in Paras so that each line of a
235
244
// / paragraph has lines of maximum length MaxLineLen and is offset by the
@@ -773,8 +782,8 @@ function StrWindowsLineBreaks(const Str: UnicodeString): UnicodeString;
773
782
Result := StrReplace(Result, LF, CRLF);
774
783
end ;
775
784
776
- function StrWrap (const Str: UnicodeString; const MaxLen, Margin: UInt16):
777
- UnicodeString;
785
+ function StrWrap (const Str: UnicodeString; const MaxLen, Margin: UInt16;
786
+ const FirstLineOffset: Int16): UnicodeString; overload ;
778
787
var
779
788
Word: UnicodeString; // next word in input Str
780
789
Line: UnicodeString; // current output line
@@ -783,14 +792,25 @@ function StrWrap(const Str: UnicodeString; const MaxLen, Margin: UInt16):
783
792
// -------------------------------------------------------------------------
784
793
// / Adds a line of text to output, offseting line by Margin spaces
785
794
procedure AddLine (const Line: string);
795
+ var
796
+ AdjustedMargin: UInt16;
786
797
begin
798
+ AdjustedMargin := Margin;
787
799
if Result <> ' ' then // not first line: insert new line
788
- Result := Result + EOL;
789
- Result := Result + StrOfSpaces(Margin) + Line;
800
+ Result := Result + EOL
801
+ else // 1st line - adjust margin
802
+ AdjustedMargin := Margin + FirstLineOffset;
803
+ Result := Result + StrOfSpaces(AdjustedMargin) + Line;
790
804
end ;
791
805
// -------------------------------------------------------------------------
792
806
793
807
begin
808
+ // FirstLineOffset, if negative, must have absolute value <= Margin and
809
+ // FirstLineOffset, if positive, added to Margin must fit in UInt16
810
+ Assert((Margin + FirstLineOffset >= 0 )
811
+ and (Margin + FirstLineOffset < High(Margin)),
812
+ ' StrWrap: FirstLineOffset + Margin out of range'
813
+ );
794
814
// Get all words in Str
795
815
Words := TStringList.Create;
796
816
try
0 commit comments