@@ -269,6 +269,16 @@ procedure StrArrayToStrList(const SA: array of string; const SL: TStrings);
269
269
function StrIsEmpty (const S: string; const IgnoreWhiteSpace: Boolean = False):
270
270
Boolean;
271
271
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;
272
282
273
283
implementation
274
284
@@ -769,15 +779,14 @@ function StrWrap(const Str: UnicodeString; const MaxLen, Margin: Integer):
769
779
Word: UnicodeString; // next word in input Str
770
780
Line: UnicodeString; // current output line
771
781
Words: TStringList; // list of words in input Str
772
- I: Integer; // loops thru all words in input Str
773
782
774
783
// -------------------------------------------------------------------------
775
784
// / Adds a line of text to output, offseting line by Margin spaces
776
785
procedure AddLine (const Line: string);
777
786
begin
778
787
if Result <> ' ' then // not first line: insert new line
779
788
Result := Result + EOL;
780
- Result := Result + StringOfChar( ' ' , Margin) + Line;
789
+ Result := Result + StrOfSpaces( Margin) + Line;
781
790
end ;
782
791
// -------------------------------------------------------------------------
783
792
@@ -789,9 +798,8 @@ function StrWrap(const Str: UnicodeString; const MaxLen, Margin: Integer):
789
798
Result := ' ' ;
790
799
Line := ' ' ;
791
800
// Loop for each word in Str
792
- for I := 0 to Pred( Words.Count) do
801
+ for Word in Words do
793
802
begin
794
- Word := Words[I];
795
803
if Length(Line) + Length(Word) + 1 <= MaxLen then
796
804
begin
797
805
// Word fits on current line: add it
@@ -904,5 +912,17 @@ function StrIsEmpty(const S: string; const IgnoreWhiteSpace: Boolean = False):
904
912
Result := S = ' ' ;
905
913
end ;
906
914
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
+
907
927
end .
908
928
0 commit comments