Wiki Home

UUEncode


Namespace: WIN_COM_API
How to UUEncode in VFP?
FUNCTION uuencode
LPARAMETERS tcL
LOCAL lnN, lnC, lnE, lcU, lnI
lnN=0
lcU=''
FOR lnI = 1 TO LEN(tcL)
  lnN = lnN + 1 
  lnC = ASC(substr(tcL, lnI, 1))
  DO CASE
    CASE (lnN == 1)
      lcU = lcU + uuencode_one(int(lnC/4))
      lnE = lnC % 4
    CASE (lnN == 2)
      lcU = lcU + uuencode_one(lnE * 16 + int(lnC/16))
      lnE = lnC % 16
    CASE (lnN == 3)
      lcU = lcU + uuencode_one(lnE * 4 + int(lnC/64))
      lcU = lcU + uuencode_one(lnC % 64)
      lnN = 0
  ENDCASE
ENDFOR
lnC=0
DO CASE
  CASE (lnN == 1)
    lcU = lcU + uuencode_one(lnE * 16 + int(lnC/16))
    lcU = lcU + "=="
  CASE (lnN == 2)
    lcU = lcU + uuencode_one(lnE * 4 + int(lnC/64))
    lcU = lcU + "="
ENDCASE
return lcU
ENDFUNC

FUNCTION uuencode_one
LPARAMETERS tnV
RETURN ICASE( (tnV < 26), chr(tnV+65)    ;
            , (tnV < 52), chr(tnV-26+97) ;
            , (tnV < 62), chr(tnV-52+48) ;
            , (tnV == 62), "+" ;
            , (tnV == 63), "/", ;
            '' )
ENDFUNC
( Topic last updated: 2008.09.26 09:06:59 PM )