Back to index

lightning-sunbird  0.9+nobinonly
Defines | Typedefs | Functions | Variables
nsEscape.cpp File Reference
#include "extern.h"
#include "extra.h"
#include "nsEscape.h"

Go to the source code of this file.

Defines

#define UNHEX(C)
#define IS_OK(C)   (netCharType[((unsigned int) (C))] & (mask))
#define HEX_ESCAPE   '%'

Typedefs

typedef int PRInt32

Functions

NS_COM char * nsEscape (const char *str, nsEscapeMask mask)
 Escape the given string according to mask.
NS_COM char * nsEscapeCount (const char *str, PRInt32 len, nsEscapeMask mask, PRInt32 *out_len)
NS_COM char * nsUnescape (char *str)
NS_COM PRInt32 nsUnescapeCount (char *str)

Variables

const int netCharType [256]

Define Documentation

#define HEX_ESCAPE   '%'

Definition at line 86 of file nsEscape.cpp.

#define IS_OK (   C)    (netCharType[((unsigned int) (C))] & (mask))

Definition at line 85 of file nsEscape.cpp.

#define UNHEX (   C)
Value:
((C >= '0' && C <= '9') ? C - '0' : \
     ((C >= 'A' && C <= 'F') ? C - 'A' + 10 : \
     ((C >= 'a' && C <= 'f') ? C - 'a' + 10 : 0)))

Definition at line 79 of file nsEscape.cpp.


Typedef Documentation

typedef int PRInt32

Definition at line 56 of file nsEscape.cpp.


Function Documentation

NS_COM char* nsEscape ( const char *  str,
nsEscapeMask  mask 
)

Escape the given string according to mask.

Parameters:
strThe string to escape
maskHow to escape the string
Returns:
A newly allocated escaped string that must be free'd with nsCRT::free, or null on failure

Definition at line 89 of file nsEscape.cpp.

{
    if(!str)
        return NULL;
    return nsEscapeCount(str, lstrlen(str), mask, NULL);
}

Here is the call graph for this function:

NS_COM char* nsEscapeCount ( const char *  str,
PRInt32  len,
nsEscapeMask  mask,
PRInt32 out_len 
)

Definition at line 98 of file nsEscape.cpp.

{
       if (!str)
              return 0;

    int i, extra = 0;
    char* hexChars = "0123456789ABCDEF";

       register const unsigned char* src = (const unsigned char *) str;
    for (i = 0; i < len; i++)
       {
        if (!IS_OK(*src++))
            extra += 2; /* the escape, plus an extra byte for each nibble */
       }

       char* result = (char *)NS_GlobalAlloc(len + extra + 1);
    if (!result)
        return 0;

    register unsigned char* dst = (unsigned char *) result;
       src = (const unsigned char *) str;
       if (mask == url_XPAlphas)
       {
           for (i = 0; i < len; i++)
              {
                     unsigned char c = *src++;
                     if (IS_OK(c))
                            *dst++ = c;
                     else if (c == ' ')
                            *dst++ = '+'; /* convert spaces to pluses */
                     else 
                     {
                            *dst++ = HEX_ESCAPE;
                            *dst++ = hexChars[c >> 4];  /* high nibble */
                            *dst++ = hexChars[c & 0x0f];       /* low nibble */
                     }
              }
       }
       else
       {
           for (i = 0; i < len; i++)
              {
                     unsigned char c = *src++;
                     if (IS_OK(c))
                            *dst++ = c;
                     else 
                     {
                            *dst++ = HEX_ESCAPE;
                            *dst++ = hexChars[c >> 4];  /* high nibble */
                            *dst++ = hexChars[c & 0x0f];       /* low nibble */
                     }
              }
       }

    *dst = '\0';     /* tack on eos */
       if(out_len)
              *out_len = dst - (unsigned char *) result;
    return result;
}

Here is the call graph for this function:

NS_COM char* nsUnescape ( char *  str)

Definition at line 164 of file nsEscape.cpp.

{
       nsUnescapeCount(str);
       return str;
}

Here is the call graph for this function:

NS_COM PRInt32 nsUnescapeCount ( char *  str)

Definition at line 172 of file nsEscape.cpp.

{
    register char *src = str;
    register char *dst = str;

    while (*src)
        if (*src != HEX_ESCAPE)
              *dst++ = *src++;
        else  
              {
              src++; /* walk over escape */
              if (*src)
            {
              *dst = UNHEX(*src) << 4;
              src++;
            }
              if (*src)
            {
              *dst = (*dst + UNHEX(*src));
              src++;
            }
              dst++;
        }

    *dst = 0;
    return (int)(dst - str);

} /* NET_UnEscapeCnt */

Variable Documentation

Initial value:

    
    {    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 
               0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,  
               0,0,0,0,0,0,0,0,0,0,7,4,0,7,7,4,  
         7,7,7,7,7,7,7,7,7,7,0,0,0,7,0,0, 
            0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,     
            
            
            7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,7,     
            0,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,     
            7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,     
               0, }

Definition at line 58 of file nsEscape.cpp.