Parse one or more JSON attribute objects from a line.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line |
Source line containing one or more JSON attribute objects |
||
| type(onnx_attribute_type), | intent(inout), | allocatable | :: | attrs(:) |
Destination list of parsed attributes |
|
| integer, | intent(inout) | :: | n_attrs |
Number of valid attributes in attrs |
subroutine parse_json_attribute(line, attrs, n_attrs) !! Parse one or more JSON attribute objects from a line. implicit none ! Arguments character(*), intent(in) :: line !! Source line containing one or more JSON attribute objects type(onnx_attribute_type), allocatable, intent(inout) :: attrs(:) !! Destination list of parsed attributes integer, intent(inout) :: n_attrs !! Number of valid attributes in attrs ! Local variables integer :: pos, brace_start, brace_end, depth, k !! Scan positions and brace depth state pos = 1 do while(pos .le. len_trim(line)) brace_start = index(line(pos:), '{') if(brace_start .eq. 0) exit brace_start = pos + brace_start - 1 depth = 0 brace_end = 0 do k = brace_start, len_trim(line) if(line(k:k) .eq. '{') depth = depth + 1 if(line(k:k) .eq. '}') depth = depth - 1 if(depth .eq. 0)then brace_end = k exit end if end do if(brace_end .eq. 0) exit call parse_single_json_attribute( & line(brace_start:brace_end), attrs, n_attrs) pos = brace_end + 1 end do end subroutine parse_json_attribute