Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(string), | intent(in) | :: | self | The string. |
||
character(kind=CK,len=*), | intent(in) | :: | codec | Encoding codec. |
Encoded string.
Return a string encoded accordingly the codec.
```fortran type(string) :: astring astring = 'How are you?' print '(A)', astring%encode(codec='base64')//'' ! print "SG93IGFyZSB5b3U/"
elemental function encode(self, codec) result(encoded)
!---------------------------------------------------------------------------------------------------------------------------------
!< Return a string encoded accordingly the codec.
!<
!< @note Only BASE64 codec is currently available.
!<
!<### Example
!<
!<```fortran
!< type(string) :: astring
!< astring = 'How are you?'
!< print '(A)', astring%encode(codec='base64')//'' ! print "SG93IGFyZSB5b3U/"
!---------------------------------------------------------------------------------------------------------------------------------
class(string), intent(in) :: self !< The string.
character(kind=CK, len=*), intent(in) :: codec !< Encoding codec.
type(string) :: encoded !< Encoded string.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
if (allocated(self%raw)) then
encoded = codec
select case(encoded%upper()//'')
case('BASE64')
call b64_encode(s=self%raw, code=encoded%raw)
endselect
endif
return
!---------------------------------------------------------------------------------------------------------------------------------
endfunction encode