Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self | The string. |
||
integer, | intent(in) | :: | width | Final width of filled string. |
||
logical, | intent(in), | optional | :: | right | Fill on the right instead of left. |
|
character(kind=CK,len=1), | intent(in), | optional | :: | filling_char | Filling character (default "0"). |
Filled string.
Pad string on the left (or right) with zeros (or other char) to fill width.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | public | :: | right_ | Fill on the right instead of left, local variable. |
|||
character(kind=CK,len=1), | public | :: | filling_char_ | Filling character (default "0"), local variable. |
elemental function fill(self, width, right, filling_char) result(filled)
!---------------------------------------------------------------------------------------------------------------------------------
!< Pad string on the left (or right) with zeros (or other char) to fill width.
!---------------------------------------------------------------------------------------------------------------------------------
class(string), intent(in) :: self !< The string.
integer, intent(in) :: width !< Final width of filled string.
logical, intent(in), optional :: right !< Fill on the right instead of left.
character(kind=CK, len=1), intent(in), optional :: filling_char !< Filling character (default "0").
type(string) :: filled !< Filled string.
logical :: right_ !< Fill on the right instead of left, local variable.
character(kind=CK, len=1) :: filling_char_ !< Filling character (default "0"), local variable.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
if (allocated(self%raw)) then
if (width>len(self%raw)) then
right_ = .false. ; if (present(right)) right_ = right
filling_char_ = '0' ; if (present(filling_char)) filling_char_ = filling_char
if (.not.right_) then
filled%raw = repeat(filling_char_, width-len(self%raw))//self%raw
else
filled%raw = self%raw//repeat(filling_char_, width-len(self%raw))
endif
endif
endif
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction fill