subroutinehtml_escapepure
pure subroutine html_escape(text, b, quotes)
Append text, escaped for HTML.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| text | character(len=*) | in | the text | |
| b | type(buffer_t) | inout | the buffer | |
| quotes | logical | in | true to escape |
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, '&')
case ('<'); call add(b, '<')
case ('>'); call add(b, '>')
case default; call add(b, '"')
end select
end select
end do
if (start <= len(text)) call add(b, text(start:))
end subroutine html_escape