Width of tokens first:lend up to the end of the first code token that has another code token
after it on the line (the shortest first part of a split), or a huge value if there is none.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(writer_t), | intent(in) | :: | w |
the output and the alignment state |
||
| character(len=*), | intent(in) | :: | src |
the source text |
||
| type(token_list_t), | intent(in) | :: | tokens |
its tokens |
||
| integer, | intent(in) | :: | first |
first token of the part of the line to measure |
||
| integer, | intent(in) | :: | lend |
last token of the line, its line break if it has one |
integer function first_piece_width(w, src, tokens, first, lend) result(width) !! Width of tokens `first:lend` up to the end of the first code token that has another code token !! after it on the line (the shortest first part of a split), or a huge value if there is none. type(writer_t), intent(in) :: w !! the output and the alignment state character(len=*), intent(in) :: src !! the source text type(token_list_t), intent(in) :: tokens !! its tokens integer, intent(in) :: first !! first token of the part of the line to measure integer, intent(in) :: lend !! last token of the line, its line break if it has one type(piece_t), allocatable :: pieces(:) integer :: k, m, total width = huge(1)/2 call line_pieces(w, src, tokens, first, lend, pieces) total = 0 do k = 1, size(pieces) associate (text => src(pieces(k)%first:pieces(k)%last)) if (pieces(k)%blanks > 0) then total = total + pieces(k)%blanks else if (scan(text, achar(10)//achar(13)) > 0) return total = total + utf8_width(text) end if end associate if (pieces(k)%tok == 0) cycle if (.not. is_code_kind(tokens%tok(pieces(k)%tok)%kind)) cycle if (pieces(k)%tok == first .and. tokens%tok(first)%kind == TK_INT) cycle ! a statement label do m = k + 1, size(pieces) if (pieces(m)%tok == 0) cycle if (is_code_kind(tokens%tok(pieces(m)%tok)%kind) .and. .not. tokens%tok(pieces(m)%tok)%glued) then width = total return end if exit end do end do end function first_piece_width