string_end Function

private function string_end(src, i, flags) result(j)

Last byte of a string literal whose opening quote is at i. Handles doubled quotes and continuation lines; flags reports STR_* conditions.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: src

source text

integer, intent(in) :: i

byte of the opening quote

integer, intent(out) :: flags

STR_* bit flags of the literal

Return Value integer


Calls

proc~~string_end~~CallsGraph proc~string_end string_end proc~is_blank is_blank proc~string_end->proc~is_blank proc~line_end line_end proc~string_end->proc~line_end proc~only_blanks_to_eol only_blanks_to_eol proc~string_end->proc~only_blanks_to_eol proc~peek peek proc~string_end->proc~peek proc~only_blanks_to_eol->proc~line_end proc~last_nonblank last_nonblank proc~only_blanks_to_eol->proc~last_nonblank proc~last_nonblank->proc~is_blank

Called by

proc~~string_end~~CalledByGraph proc~string_end string_end proc~tokenize tokenize proc~tokenize->proc~string_end proc~format_text format_text proc~format_text->proc~tokenize proc~convert_relational convert_relational proc~format_text->proc~convert_relational proc~format_pass format_pass proc~format_text->proc~format_pass proc~limit_diagnostics limit_diagnostics proc~format_text->proc~limit_diagnostics proc~long_code_lines long_code_lines proc~format_text->proc~long_code_lines proc~sort_use sort_use proc~format_text->proc~sort_use proc~split_long_lines split_long_lines proc~format_text->proc~split_long_lines proc~relayout relayout proc~format_text->proc~relayout proc~parse_source parse_source proc~parse_source->proc~tokenize proc~same_code same_code proc~same_code->proc~tokenize proc~code_signature code_signature proc~same_code->proc~code_signature proc~code_signature->proc~parse_source proc~convert_relational->proc~parse_source proc~format_pass->proc~parse_source proc~limit_diagnostics->proc~parse_source proc~long_code_lines->proc~parse_source proc~process_text process_text proc~process_text->proc~format_text proc~sort_use->proc~parse_source proc~split_long_lines->proc~parse_source proc~process_file process_file proc~process_file->proc~process_text proc~process_stdin process_stdin proc~process_stdin->proc~process_text proc~relayout->proc~format_pass proc~run run proc~run->proc~process_file proc~run->proc~process_stdin

Source Code

integer function string_end(src, i, flags) result(j)
    !! Last byte of a string literal whose opening quote is at `i`. Handles doubled quotes and
    !! continuation lines; `flags` reports STR_* conditions.
    character(len=*), intent(in) :: src   !! source text
    integer, intent(in) :: i              !! byte of the opening quote
    integer, intent(out) :: flags         !! STR_* bit flags of the literal
    character :: q, c
    integer :: k

    flags = 0
    q = src(i:i)
    j = i + 1
    do
        if (j > len(src)) then
            flags = ior(flags, STR_UNTERMINATED)
            j = len(src)
            return
        end if
        c = src(j:j)
        if (c == q) then
            if (peek(src, j + 1) /= q) return
            j = j + 2
        else if (c == LF .or. c == CR) then
            flags = ior(flags, STR_UNTERMINATED)
            j = j - 1
            return
        else if (c == '&' .and. only_blanks_to_eol(src, j + 1)) then
            ! character context continued on the next line
            k = line_end(src, j) + 1          ! the line break
            if (k > len(src)) then
                j = len(src)
                flags = ior(flags, STR_UNTERMINATED)
                return
            end if
            if (src(k:k) == CR .and. peek(src, k + 1) == LF) k = k + 1
            k = k + 1                          ! start of the continuation line
            flags = ior(flags, STR_MULTILINE)
            j = k
            do while (is_blank(peek(src, j)))
                j = j + 1
            end do
            if (peek(src, j) == '&') then
                j = j + 1
            else
                flags = ior(flags, STR_RAW_CONT)
                j = k
            end if
        else
            j = j + 1
        end if
    end do
end function string_end