Skip to content

Commit 39eec81

Browse files
added comments to explain the right padding and shifted RHS completely to the next line
Co-authored-by: Milan Curcic <caomaco@gmail.com>
1 parent 7bc4b3a commit 39eec81

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/stdlib_strings.f90

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,10 @@ pure function padr_string_default(string, output_length) result(res)
736736
character(len=max(len(string), output_length)) :: char_output
737737
type(string_type) :: res
738738

739+
! We're taking advantage of `char_output` being longer than `string` and
740+
! initialized with whitespaces. By casting `string` to a `character`
741+
! type and back to `string_type`, we're effectively right-padding
742+
! `string` with spaces, so we don't need to pad explicitly.
739743
char_output = char(string)
740744
res = string_type(char_output)
741745

@@ -780,8 +784,8 @@ pure function padr_char_pad_with(string, output_length, pad_with) result(res)
780784

781785
res = string
782786
if (string_length < output_length) then
783-
res(string_length + 1 : output_length) = repeat(pad_with, &
784-
& output_length - string_length)
787+
res(string_length + 1 : output_length) = &
788+
repeat(pad_with, output_length - string_length)
785789
end if
786790

787791
end function padr_char_pad_with

0 commit comments

Comments
 (0)