Skip to content

Commit 74bb5ba

Browse files
committed
Merge branch 'pad' of https://github.com/Aman-Godara/stdlib into pad
2 parents 0b91973 + 39eec81 commit 74bb5ba

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
@@ -748,6 +748,10 @@ pure function padr_string_default(string, output_length) result(res)
748748
character(len=max(len(string), output_length)) :: char_output
749749
type(string_type) :: res
750750

751+
! We're taking advantage of `char_output` being longer than `string` and
752+
! initialized with whitespaces. By casting `string` to a `character`
753+
! type and back to `string_type`, we're effectively right-padding
754+
! `string` with spaces, so we don't need to pad explicitly.
751755
char_output = char(string)
752756
res = string_type(char_output)
753757

@@ -792,8 +796,8 @@ pure function padr_char_pad_with(string, output_length, pad_with) result(res)
792796

793797
res = string
794798
if (string_length < output_length) then
795-
res(string_length + 1 : output_length) = repeat(pad_with, &
796-
& output_length - string_length)
799+
res(string_length + 1 : output_length) = &
800+
repeat(pad_with, output_length - string_length)
797801
end if
798802

799803
end function padr_char_pad_with

0 commit comments

Comments
 (0)