@@ -269,6 +269,16 @@ procedure StrArrayToStrList(const SA: array of string; const SL: TStrings);
269269function StrIsEmpty (const S: string; const IgnoreWhiteSpace: Boolean = False):
270270 Boolean;
271271
272+ // / <summary>Returns a string containing Count copies of character Ch.
273+ // / </summary>
274+ // / <remarks>If Count is zero then the empty string is returned.</remarks>
275+ function StrOfChar (const Ch: Char; const Count: Word): string;
276+
277+ // / <summary>Returns a string of a given number of spaces.</summary>
278+ // / <param name="Count">Word [in] Required number of spaces.</param>
279+ // / <returns>string. Required number of spaces.</returns>
280+ // / <remarks>If Count is zero then an empty string is returned.</remarks>
281+ function StrOfSpaces (const Count: Word): string;
272282
273283implementation
274284
@@ -769,15 +779,14 @@ function StrWrap(const Str: UnicodeString; const MaxLen, Margin: Integer):
769779 Word: UnicodeString; // next word in input Str
770780 Line: UnicodeString; // current output line
771781 Words: TStringList; // list of words in input Str
772- I: Integer; // loops thru all words in input Str
773782
774783 // -------------------------------------------------------------------------
775784 // / Adds a line of text to output, offseting line by Margin spaces
776785 procedure AddLine (const Line: string);
777786 begin
778787 if Result <> ' ' then // not first line: insert new line
779788 Result := Result + EOL;
780- Result := Result + StringOfChar( ' ' , Margin) + Line;
789+ Result := Result + StrOfSpaces( Margin) + Line;
781790 end ;
782791 // -------------------------------------------------------------------------
783792
@@ -789,9 +798,8 @@ function StrWrap(const Str: UnicodeString; const MaxLen, Margin: Integer):
789798 Result := ' ' ;
790799 Line := ' ' ;
791800 // Loop for each word in Str
792- for I := 0 to Pred( Words.Count) do
801+ for Word in Words do
793802 begin
794- Word := Words[I];
795803 if Length(Line) + Length(Word) + 1 <= MaxLen then
796804 begin
797805 // Word fits on current line: add it
@@ -904,5 +912,17 @@ function StrIsEmpty(const S: string; const IgnoreWhiteSpace: Boolean = False):
904912 Result := S = ' ' ;
905913end ;
906914
915+ function StrOfChar (const Ch: Char; const Count: Word): string;
916+ begin
917+ if Count = 0 then
918+ Exit(' ' );
919+ Result := System.StringOfChar(Ch, Count);
920+ end ;
921+
922+ function StrOfSpaces (const Count: Word): string;
923+ begin
924+ Result := StrOfChar(' ' , Count);
925+ end ;
926+
907927end .
908928
0 commit comments