Width of tokens first:lend as they will be written on one line, without the line break and
without a trailing comment (compilers only limit the length of the code). A comment on a line
of its own counts.
| 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 line_width(w, src, tokens, first, lend) result(width) !! Width of tokens `first:lend` as they will be written on one line, without the line break and !! without a trailing comment (compilers only limit the length of the code). A comment on a line !! of its own counts. 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, j, before_blank call line_pieces(w, src, tokens, first, lend, pieces) width = 0 before_blank = 0 do k = 1, size(pieces) if (pieces(k)%tok > 0 .and. k > 1) then if (tokens%tok(pieces(k)%tok)%kind == TK_COMMENT) then width = before_blank ! a trailing comment, and the blanks before it return end if end if if (pieces(k)%blanks > 0) then width = width + pieces(k)%blanks cycle end if associate (text => src(pieces(k)%first:pieces(k)%last)) if (pieces(k)%tok > 0) before_blank = width + utf8_width(text) j = scan(text, achar(10)//achar(13)) if (j > 0) then ! a line break, or a token continued on the next line width = width + utf8_width(text(1:j - 1)) return end if width = width + utf8_width(text) end associate end do end function line_width