Last byte of a string literal whose opening quote is at i. Handles doubled quotes and
continuation lines; flags reports STR_* conditions.
| Type | Intent | Optional | 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 |
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