subroutineurl_quote
subroutine url_quote(text, out)
Percent-encode the characters of text that are not safe in a URL.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| text | character(len=*) | in | the text | |
| out | character(len=:) | out | allocatable | the result |
Source
Show the code
subroutine url_quote(text, out)
character(len=*), intent(in) :: text !! the text
character(len=:), allocatable, intent(out) :: out !! the result
character(len=*), parameter :: HEX = '0123456789ABCDEF'
character(len=*), parameter :: SAFE = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-~/'
integer :: k, c
out = ''
do k = 1, len(text)
if (index(SAFE, text(k:k)) > 0) then
out = out//text(k:k)
else
c = iand(ichar(text(k:k)), 255)
out = out//'%'//HEX(c/16 + 1:c/16 + 1)//HEX(mod(c, 16) + 1:mod(c, 16) + 1)
end if
end do
end subroutine url_quote