fdoc

subroutinehtml_escapepure

pure subroutine html_escape(text, b, quotes)

Append text, escaped for HTML.

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)in

the text

btype(buffer_t)inout

the buffer

quoteslogicalin

true to escape " as well, for attribute values

Calls

Source

Show the code
pure subroutine html_escape(text, b, quotes)
    character(len=*), intent(in) :: text    !! the text
    type(buffer_t), intent(inout) :: b      !! the buffer
    logical, intent(in) :: quotes           !! true to escape `"` as well, for attribute values
    integer :: k, start

    start = 1
    do k = 1, len(text)
        select case (text(k:k))
        case ('&', '<', '>', '"')
            if (text(k:k) == '"' .and. .not. quotes) cycle
            if (k > start) call add(b, text(start:k - 1))
            start = k + 1
            select case (text(k:k))
            case ('&'); call add(b, '&amp;')
            case ('<'); call add(b, '&lt;')
            case ('>'); call add(b, '&gt;')
            case default; call add(b, '&quot;')
            end select
        end select
    end do
    if (start <= len(text)) call add(b, text(start:))
end subroutine html_escape

Graphs

Calls

Called by