decode Function

private elemental function decode(self, codec) result(decoded)

Return a string decoded accordingly the codec.

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

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)

Decoded string.


Calls

proc~~decode~~CallsGraph proc~decode stringifor_string_t::string%decode b64_decode b64_decode proc~decode->b64_decode proc~strip stringifor_string_t::string%strip proc~decode->proc~strip proc~upper stringifor_string_t::string%upper proc~decode->proc~upper

Contents

Source Code


Source Code

   elemental function decode(self, codec) result(decoded)
   !< Return a string decoded accordingly the codec.
   !<
   !< @note Only BASE64 codec is currently available.
   !<
   !<```fortran
   !< type(string) :: astring
   !< astring = 'SG93IGFyZSB5b3U/'
   !< print '(L1)', astring%decode(codec='base64')//''=='How are you?'
   !<```
   !=> T <<<
   class(string),             intent(in) :: self    !< The string.
   character(kind=CK, len=*), intent(in) :: codec   !< Encoding codec.
   type(string)                          :: decoded !< Decoded string.
   type(string)                          :: codec_u !< Encoding codec in upper case string.

   if (allocated(self%raw)) then
     decoded = self
     codec_u = codec
     select case(codec_u%upper()//'')
     case('BASE64')
       call b64_decode(code=self%raw, s=decoded%raw)
     endselect
     decoded = decoded%strip(remove_nulls=.true.)
   endif
   endfunction decode