Skip to content

Commit 0ff2014

Browse files
committed
Update UStrUtils unit & update other unit re changes
* Add new StrOfChar and StrOfSpaces functions * Refactor to use StrOfSpaces instead of StringOfChar routine. * Update indexed for loop to for .. in loop FmSWAGImportDlg: Replace StringOfChar routine call with StrOfChar
1 parent 75ddfcc commit 0ff2014

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

Src/FmSWAGImportDlg.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ procedure TSWAGImportDlg.PreviewSelectedPacket;
812812
FullPacket.FileName,
813813
FullPacket.Title,
814814
FullPacket.Author,
815-
StringOfChar('-', 80),
815+
StrOfChar('-', 80),
816816
StrWindowsLineBreaks(FullPacket.SourceCode)
817817
]
818818
);

Src/UStrUtils.pas

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ procedure StrArrayToStrList(const SA: array of string; const SL: TStrings);
269269
function 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

273283
implementation
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 = '';
905913
end;
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+
907927
end.
908928

0 commit comments

Comments
 (0)