encode Function

private elemental function encode(self, codec) result(encoded)

Return a string encoded accordingly the codec.

 type(string) :: astring
 astring = 'How are you?'
 print '(L1)', astring%encode(codec='base64')//''=='SG93IGFyZSB5b3U/'

Type Bound

string

Arguments

Type IntentOptional Attributes Name
class(string), intent(in) :: self

The string.

character(kind=CK, len=*), intent(in) :: codec

Encoding codec.

Return Value type(string)

Encoded string.


Calls

proc~~encode~~CallsGraph proc~encode stringifor_string_t::string%encode b64_encode b64_encode proc~encode->b64_encode proc~upper stringifor_string_t::string%upper proc~encode->proc~upper

Contents

Source Code


Source Code

   elemental function encode(self, codec) result(encoded)
   !< Return a string encoded accordingly the codec.
   !<
   !< @note Only BASE64 codec is currently available.
   !<
   !<```fortran
   !< type(string) :: astring
   !< astring = 'How are you?'
   !< print '(L1)', astring%encode(codec='base64')//''=='SG93IGFyZSB5b3U/'
   !<```
   !=> T <<<
   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
   endfunction encode