subroutineformat_stringprivate
subroutine format_string(c, text, args, v)
text.format(args), for fields {} and {n}.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| text | character(len=*) | in | the format | |
| args | type(value_t) | in | dimension(:) | the arguments |
| v | type(value_t) | out | the result |
Calls
Source
Show the code
subroutine format_string(c, text, args, v)
type(fypp_t), intent(inout) :: c !! the state
character(len=*), intent(in) :: text !! the format
type(value_t), intent(in) :: args(:) !! the arguments
type(value_t), intent(out) :: v !! the result
type(buffer_t) :: b
character(len=:), allocatable :: joined
integer :: i, close_brace, field, automatic, status
i = 1
automatic = 0
do while (i <= len(text))
if (text(i:i) /= '{') then
call add(b, text(i:i))
i = i + 1
cycle
end if
close_brace = index(text(i:), '}')
if (close_brace == 0) then
call fail(c, 'a format is not closed: '//text)
return
end if
if (close_brace == 2) then
field = automatic
automatic = automatic + 1
else
call digits_value(text(i + 1:i + close_brace - 2), field, status)
if (status /= 0) then
call fail(c, 'the format is not supported: '//text)
return
end if
end if
if (field >= size(args)) then
call fail(c, 'a format has too few arguments: '//text)
return
end if
call write_value(args(field + 1), .false., b)
i = i + close_brace
end do
call take(b, joined)
call make_string(joined, v)
end subroutine format_string