Back to index

lightning-sunbird  0.9+nobinonly
Static Public Member Functions
UMimeEncode Class Reference

#include <nsImportTranslator.h>

List of all members.

Static Public Member Functions

static PRUint32 GetBufferSize (PRUint32 inByes)
static PRUint32 ConvertBuffer (const PRUint8 *pIn, PRUint32 inLen, PRUint8 *pOut, PRUint32 maxLen=72, PRUint32 firstLineLen=72, const char *pEolStr=nsnull)

Detailed Description

Definition at line 47 of file nsImportTranslator.h.


Member Function Documentation

PRUint32 UMimeEncode::ConvertBuffer ( const PRUint8 pIn,
PRUint32  inLen,
PRUint8 pOut,
PRUint32  maxLen = 72,
PRUint32  firstLineLen = 72,
const char *  pEolStr = nsnull 
) [static]

Definition at line 250 of file nsImportTranslator.cpp.

{

       PRUint32      pos = 0;
       PRUint32      len = 0;
       PRUint32      lineLen = 0;
       PRUint32      maxLine = firstLineLen;
       int    eolLen = 0;
       if (pEolStr)
              eolLen = strlen( pEolStr);

       while ((pos + 2) < inLen) {
              // Encode 3 bytes
              *pOut = gBase64[*pIn >> 2];
              pOut++; len++; lineLen++;
              *pOut = gBase64[(((*pIn) & 0x3)<< 4) | (((*(pIn + 1)) & 0xF0) >> 4)];
              pIn++; pOut++; len++; lineLen++;
              *pOut = gBase64[(((*pIn) & 0xF) << 2) | (((*(pIn + 1)) & 0xC0) >>6)];
              pIn++; pOut++; len++; lineLen++;
              *pOut = gBase64[(*pIn) & 0x3F];
              pIn++; pOut++; len++; lineLen++;
              pos += 3;
              if (lineLen >= maxLine) {
                     lineLen = 0;
                     maxLine = maxLen;
                     if (pEolStr) {
                            memcpy( pOut, pEolStr, eolLen);
                            pOut += eolLen;
                            len += eolLen;
                     }
              }
       }

       if ((pos < inLen) && ((lineLen + 3) > maxLine)) {
              lineLen = 0;
              maxLine = maxLen;
              if (pEolStr) {
                     memcpy( pOut, pEolStr, eolLen);
                     pOut += eolLen;
                     len += eolLen;
              }
       }

       if (pos < inLen) {
              // Get the last few bytes!
              *pOut = gBase64[*pIn >> 2];
              pOut++; len++;
              pos++;
              if (pos < inLen) {
                     *pOut = gBase64[(((*pIn) & 0x3)<< 4) | (((*(pIn + 1)) & 0xF0) >> 4)];
                     pIn++; pOut++; pos++; len++;
                     if (pos < inLen) {
                            // Should be dead code!! (Then why is it here doofus?)
                            *pOut = gBase64[(((*pIn) & 0xF) << 2) | (((*(pIn + 1)) & 0xC0) >>6)];
                            pIn++; pOut++; len++;
                            *pOut = gBase64[(*pIn) & 0x3F];
                            pos++; pOut++; len++;
                     }
                     else {
                            *pOut = gBase64[(((*pIn) & 0xF) << 2)];
                            pOut++; len++;
                            *pOut = '=';
                            pOut++; len++;
                     }
              }
              else {
                     *pOut = gBase64[(((*pIn) & 0x3)<< 4)];
                     pOut++; len++;
                     *pOut = '=';
                     pOut++; len++;
                     *pOut = '=';
                     pOut++; len++;
              }      
       }

       *pOut = 0;

       return( len);
}

Here is the call graph for this function:

Definition at line 233 of file nsImportTranslator.cpp.

{
       // it takes 4 base64 bytes to represent 3 regular bytes
       inBytes += 3;
       inBytes /= 3;
       inBytes *= 4;
       // This should be plenty, but just to be safe
       inBytes += 4;

       // now allow for end of line characters
       inBytes += ((inBytes + 39) / 40) * 4;

       return( inBytes);
}

The documentation for this class was generated from the following files: