-static inline int isurlsafe( int c )
-{
- return ( (unsigned char)( c - 'a' ) < 26 )
- || ( (unsigned char)( c - 'A' ) < 26 )
- || ( (unsigned char)( c - '0' ) < 10 )
- /* Hmm, we should not encode character that are allowed in URLs
- * (even if they are not URL-safe), nor URL-safe characters.
- * We still encode some of them because of Microsoft's crap browser.
- */
- || ( strchr( "-_.", c ) != NULL );
-}
-
-/*****************************************************************************
- * vlc_UrlEncode:
- *****************************************************************************
- * perform URL encoding
- * (you do NOT want to do URL decoding - it is not reversible - do NOT do it)
- *****************************************************************************/
-static inline char *vlc_UrlEncode( const char *psz_url )
-{
- char *psz_enc, *out;
- const unsigned char *in;
-
- psz_enc = (char *)malloc( 3 * strlen( psz_url ) + 1 );
- if( psz_enc == NULL )
- return NULL;
-
- out = psz_enc;
- for( in = (const unsigned char *)psz_url; *in; in++ )
- {
- unsigned char c = *in;
-
- if( isurlsafe( c ) )
- *out++ = (char)c;
- else
- {
- *out++ = '%';
- *out++ = ( ( c >> 4 ) >= 0xA ) ? 'A' + ( c >> 4 ) - 0xA
- : '0' + ( c >> 4 );
- *out++ = ( ( c & 0xf ) >= 0xA ) ? 'A' + ( c & 0xf ) - 0xA
- : '0' + ( c & 0xf );
- }
- }
- *out++ = '\0';
-
- return (char *)realloc( psz_enc, out - psz_enc );
-}
-
-/*****************************************************************************
- * vlc_UrlIsNotEncoded:
- *****************************************************************************
- * check if given string is not a valid URL and must hence be encoded
- *****************************************************************************/