subroutineparse_metadata
subroutine parse_metadata(text, meta)
Split project file text into metadata and body.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| text | character(len=*) | in | the file | |
| meta | type(metadata_t) | out | the result |
Calls
Source
Show the code
subroutine parse_metadata(text, meta)
character(len=*), intent(in) :: text !! the file
type(metadata_t), intent(out) :: meta !! the result
type(string_t), allocatable :: lines(:)
character(len=:), allocatable :: key, value
integer :: n, current
lines = split_lines(text)
allocate (meta%items(0))
n = 1
if (size(lines) > 0) then
if (is_marker(lines(1)%s, '-')) n = 2
end if
current = 0
do while (n <= size(lines))
associate (line => lines(n)%s)
if (strip(line) == '' .or. is_marker(line, '-') .or. is_marker(line, '.')) then
n = n + 1
exit
end if
if (match_key(line, key, value)) then
call add_value(meta, key, value, current)
else if (current > 0 .and. leading_blanks(line) >= 4) then
call push(meta%items(current)%values, strip(line))
else
exit
end if
end associate
n = n + 1
end do
meta%body = lines(n:)
end subroutine parse_metadata