percent_encode(3f) - [M_strings:ENCODE] percent-encode strings and character arrays (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
function percent_encode(text)
character(len=1),intent(in) :: text(:) character(len=;),allocatable :: percent_encodeor
function percent_encode(text)
character(len=*),intent(in) :: text character(len=;),allocatable :: percent_encode
This function percent-encodes ASCII strings or ASCII character arrays. "Reserved" characters are encoded.
URI containing spaces or most other non-alphanumeric characters must be encoded using percent encoding (aka. URL encoding).
The characters allowed in a URI are either reserved or unreserved (or a percent character as part of a percent-encoding). Reserved characters are those characters that sometimes have special meaning, while unreserved characters have no such meaning. Using percent-encoding, characters which otherwise would not be allowed are represented using allowed characters. The sets of reserved and unreserved characters and the circumstances under which certain reserved characters have special meaning have changed slightly with each revision of specifications that govern URIs and URI schemes.
According to RFC 3986, the characters in a URL have to be taken from a defined set of unreserved and reserved ASCII characters. Any other characters are not allowed in a URL.
The unreserved characters can be encoded, but should not be. The unreserved characters are:
> ABCDEFGHIJKLMNOPQRSTUVWXYZ > abcdefghijklmnopqrstuvwxyz > 0123456789-_.~The reserved characters have to be encoded only under certain circumstances. The reserved characters are:
> * ( ) ; : @ & = + $ , / ? % # [ ]
SOURCE_STRING string or character array to encode
percent_encode a string holding a percent-encoded copy of the input
Sample program:
program demo_percent_encode use M_strings, only : percent_encode use, intrinsic :: iso_fortran_env, only : stdout=>output_unit implicit none write(*,*)percent_encode([this is a string]) end program demo_percent_encodeResults:
> %5Bthis%20is%20a%20string%5D
John S. Urban
Nemo Release 3.1 | percent_encode (3m_strings) | January 10, 2025 |