pad Function

private pure function pad(value, width) result(text)

value in decimal, zero filled on the left to width characters. A value too wide to fit is not truncated; the field simply grows.

A negative value keeps its sign at the front: zero filling the text of -5 to four characters gives 00-5, which is not a number. The digits are padded to width and the sign prepended, so the answer is -0005 – sign plus four digits, which is what ISO 8601 asks for in an expanded year.

The sign is removed from the text rather than by negating value, because negating the most negative value of a kind is signed overflow.

Arguments

Type IntentOptional Attributes Name
integer(kind=default_int), intent(in) :: value
integer, intent(in) :: width

Return Value character(len=:), allocatable


Calls

proc~~pad~2~~CallsGraph proc~pad~2 pad interface~to_string to_string proc~pad~2->interface~to_string interface~zfill zfill proc~pad~2->interface~zfill proc~zfill_char zfill_char interface~zfill->proc~zfill_char proc~zfill_string zfill_string interface~zfill->proc~zfill_string interface~padl padl proc~zfill_char->interface~padl proc~zfill_string->interface~padl proc~padl_char_default padl_char_default interface~padl->proc~padl_char_default proc~padl_char_pad_with padl_char_pad_with interface~padl->proc~padl_char_pad_with proc~padl_string_default padl_string_default interface~padl->proc~padl_string_default proc~padl_string_pad_with padl_string_pad_with interface~padl->proc~padl_string_pad_with proc~padl_char_default->interface~padl proc~padl_string_default->interface~padl proc~padl_string_pad_with->interface~padl

Called by

proc~~pad~2~~CalledByGraph proc~pad~2 pad proc~format_iso8601 format_iso8601 proc~format_iso8601->proc~pad~2 proc~offset_text offset_text proc~format_iso8601->proc~offset_text proc~offset_text->proc~pad~2

Source Code

   pure function pad(value, width) result(text)
      !! `value` in decimal, zero filled on the left to `width` characters.
      !! A value too wide to fit is not truncated; the field simply grows.
      !!
      !! A negative value keeps its sign at the front: zero filling the text
      !! of `-5` to four characters gives `00-5`, which is not a number. The
      !! digits are padded to `width` and the sign prepended, so the answer is
      !! `-0005` -- sign plus four digits, which is what ISO 8601 asks for in
      !! an expanded year.
      !!
      !! The sign is removed from the text rather than by negating `value`,
      !! because negating the most negative value of a kind is signed
      !! overflow.
      integer(default_int), intent(in) :: value
      integer, intent(in) :: width
      character(len=:), allocatable :: text

      text = to_string(value)
      if (value < 0_default_int) then
         text = "-"//zfill(text(2:), width)
      else
         text = zfill(text, width)
      end if
   end function pad