Titolo: Convertire da Testo Ascii in Base64
Categoria: Codice |
|
Ultimo Aggiornamento: 27/06/04 |
Da un messaggio inviato da Pete Bozek al 4D Nug internazionale, fa la codifica in Base64 di un testo passato come blob. Gli altri due parametri opzionali indicano se inserire un salto riga e che tipo di carattere usato (il default è il Return).
` Encode_Base64_Blob
` di Peter Bozek
` http://www.inforce.sk
C_POINTER($1;$pPassedBlob)
C_BOOLEAN($2;$bInsertLineBr)
C_STRING(2;$3;$sEOL)
C_LONGINT($iPos;$iDest;$iWritten;$iWhere)
C_LONGINT($lBlobSize;$lNewSize;$lEOLLength)
C_BLOB($oTempBlob)
C_STRING(64;$encoding)
$pPassedBlob:=$1
$lBlobSize:=BLOB size($pPassedBlob->)
If ($lBlobSize>0)
`carica i parametri
If (Count parameters>1)
$bInsertLineBr:=$2
Else $bInsertLineBr:=
True End if $lEOLLength:=0
If ($bInsertLineBr)
If (Count parameters>2)
$sEOL:=$3
End if If ($sEOL="")
$sEOL:=Char(Carriage return )
End if $lEOLLength:=Length($sEOL)
End if `prepara i data
COPY BLOB($pPassedBlob->;$oTempBlob;0;0;$lBlobSize)
SET BLOB SIZE($oTempBlob;(($lBlobSize+2)\3)*3;0x0000)
SET BLOB SIZE($pPassedBlob->;0)
$lNewSize:=(($lBlobSize+2)\3)*4
If ($bInsertLineBr)
$lNewSize:=$lNewSize+(($lNewSize+75)\76)*$lEOLLength
End if SET BLOB SIZE($pPassedBlob->;$lNewSize;0x0000)
$encoding:="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$encoding:=$encoding+"abcdefghijklmnopqrstuvwxyz0123456789+/"
$iPos:=0
$iDest:=0
If ($bInsertLineBr) `start with NL
TEXT TO BLOB($sEOL;$pPassedBlob->;Text without length ;$iDest)
`$iDest:=$iDest+$lEOLLength
End if While ($iPos<$lBlobSize)
$iWhere:=($oTempBlob{$iPos} >> 2)
$pPassedBlob->{$iDest}:=Ascii($encoding[[$iWhere+1]])
$iDest:=$iDest+1
$iWhere:=(($oTempBlob{$iPos} << 4) & 0x0030) | ($oTempBlob{$iPos+1} >> 4)
$pPassedBlob->{$iDest}:=Ascii($encoding[[$iWhere+1]])
$iDest:=$iDest+1
$iWhere:=(($oTempBlob{$iPos+1} << 2) & 0x003C) | (($oTempBlob{$iPos+2} >> 6) 0x0003)
$pPassedBlob->{$iDest}:=Ascii($encoding[[$iWhere+1]])
$iDest:=$iDest+1
$iWhere:=$oTempBlob{$iPos+2} & 0x003F
$pPassedBlob->{$iDest}:=Ascii($encoding[[$iWhere+1]])
$iDest:=$iDest+1
$iPos:=$iPos+3
$iWritten:=$iWritten+4
Case of : ($iPos=($lBlobSize+1))
$pPassedBlob->{$iDest-1}:=Ascii("=")
: ($iPos=($lBlobSize+2))
$pPassedBlob->{$iDest-1}:=Ascii("=")
$pPassedBlob->{$iDest-2}:=Ascii("=")
End case If ($bInsertLineBr & ($iWritten%76=0))
TEXT TO BLOB($sEOL;$pPassedBlob->;Text without length ;$iDest)
`$iDest:=$iDest+$lEOLLength
End if End while End if
Inviato da: Umberto Migliore |
|
Visite: 14625 |
Se accedi con utente e password, puoi aggiungere dei commenti.