Back to index

lightning-sunbird  0.9+nobinonly
Defines | Enumerations | Functions
nsEscape.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define NS_COM
#define PRUnichar   char

Enumerations

enum  nsEscapeMask {
  url_XAlphas = (1<<0), url_XPAlphas = (1<<1), url_Path = (1<<2), url_All = 0,
  url_XAlphas = PR_BIT(0), url_XPAlphas = PR_BIT(1), url_Path = PR_BIT(2), url_XAlphas = (1<<0),
  url_XPAlphas = (1<<1), url_Path = (1<<2), url_XAlphas = (1<<0), url_XPAlphas = (1<<1),
  url_Path = (1<<2)
}

Functions

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

Define Documentation

Definition at line 45 of file nsEscape.h.

#define PRUnichar   char

Definition at line 46 of file nsEscape.h.


Enumeration Type Documentation

Enumerator:
url_XAlphas 
url_XPAlphas 
url_Path 
url_All 

%-escape every byte uncondtionally

url_XAlphas 

Normal escape - leave alphas intact, escape the rest.

url_XPAlphas 

As url_XAlphas, but convert spaces (0x20) to '+' and plus to %2B.

url_Path 

As url_XAlphas, but don't escape slash ('/')

url_XAlphas 
url_XPAlphas 
url_Path 
url_XAlphas 
url_XPAlphas 
url_Path 

Definition at line 49 of file nsEscape.h.

             {
       url_XAlphas          = (1<<0)
,      url_XPAlphas  = (1<<1)
,      url_Path             = (1<<2)
} nsEscapeMask;

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);
}
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;
}
NS_COM char* nsUnescape ( char *  str)

Definition at line 164 of file nsEscape.cpp.

{
       nsUnescapeCount(str);
       return str;
}
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 */