⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strings.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************** * strings.c: String related functions ***************************************************************************** * Copyright (C) 2006 the VideoLAN team * $Id: 5d1395782375435cf10a18dedb84537c235b7578 $ * * Authors: Antoine Cellerier <dionoea at videolan dot org> *          Daniel Stranger <vlc at schmaller dot de> *          Rémi Denis-Courmont <rem # videolan org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <assert.h>/* Needed by str_format_time */#include <time.h>/* Needed by str_format_meta */#include <vlc_input.h>#include <vlc_meta.h>#include <vlc_playlist.h>#include <vlc_aout.h>#include <vlc_strings.h>#include <vlc_url.h>#include <vlc_charset.h>/** * Unescape URI encoded string * \return decoded duplicated string */char *unescape_URI_duplicate( const char *psz ){    char *psz_dup = strdup( psz );    unescape_URI( psz_dup );    return psz_dup;}/** * Unescape URI encoded string in place * \return nothing */void unescape_URI( char *psz ){    unsigned char *in = (unsigned char *)psz, *out = in, c;    if( psz == NULL )        return;    while( ( c = *in++ ) != '\0' )    {        switch( c )        {            case '%':            {                char val[5], *pval = val;                unsigned long cp;                switch( c = *in++ )                {                    case '\0':                        return;                    case 'u':                    case 'U':                        if( ( *pval++ = *in++ ) == '\0' )                            return;                        if( ( *pval++ = *in++ ) == '\0' )                            return;                        c = *in++;                    default:                        *pval++ = c;                        if( ( *pval++ = *in++ ) == '\0' )                            return;                        *pval = '\0';                }                cp = strtoul( val, NULL, 0x10 );                if( cp < 0x80 )                    *out++ = cp;                else                if( cp < 0x800 )                {                    *out++ = (( cp >>  6)         | 0xc0);                    *out++ = (( cp        & 0x3f) | 0x80);                }                else                {                    assert( cp < 0x10000 );                    *out++ = (( cp >> 12)         | 0xe0);                    *out++ = (((cp >>  6) & 0x3f) | 0x80);                    *out++ = (( cp        & 0x3f) | 0x80);                }                break;            }            /* + is not a special case - it means plus, not space. */            default:                /* Inserting non-ASCII or non-printable characters is unsafe,                 * and no sane browser will send these unencoded */                if( ( c < 32 ) || ( c > 127 ) )                    *out++ = '?';                else                    *out++ = c;        }    }    *out = '\0';}/** * Decode encoded URI string * \return decoded duplicated string */char *decode_URI_duplicate( const char *psz ){    char *psz_dup = strdup( psz );    decode_URI( psz_dup );    return psz_dup;}/** * Decode encoded URI string in place * \return nothing */void decode_URI( char *psz ){    unsigned char *in = (unsigned char *)psz, *out = in, c;    if( psz == NULL )        return;    while( ( c = *in++ ) != '\0' )    {        switch( c )        {            case '%':            {                char hex[3];                if( ( ( hex[0] = *in++ ) == 0 )                 || ( ( hex[1] = *in++ ) == 0 ) )                    return;                hex[2] = '\0';                *out++ = (unsigned char)strtoul( hex, NULL, 0x10 );                break;            }            case '+':                *out++ = ' ';                break;            default:                /* Inserting non-ASCII or non-printable characters is unsafe,                 * and no sane browser will send these unencoded */                if( ( c < 32 ) || ( c > 127 ) )                    *out++ = '?';                else                    *out++ = c;        }    }    *out = '\0';    EnsureUTF8( psz );}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 );}static inline char url_hexchar( int c ){    return ( c < 10 ) ? c + '0' : c + 'A' - 10;}/** * encode_URI_component * Encodes an URI component. * * @param psz_url nul-terminated UTF-8 representation of the component. * Obviously, you can't pass an URI containing a nul character, but you don't * want to do that, do you? * * @return encoded string (must be free()'d) */char *encode_URI_component( const char *psz_url ){    char psz_enc[3 * strlen( psz_url ) + 1], *out = psz_enc;    const uint8_t *in;    for( in = (const uint8_t *)psz_url; *in; in++ )    {        uint8_t c = *in;        if( isurlsafe( c ) )            *out++ = (char)c;        else        if ( c == ' ')            *out++ = '+';        else        {            *out++ = '%';            *out++ = url_hexchar( c >> 4 );            *out++ = url_hexchar( c & 0xf );        }    }    *out++ = '\0';    return strdup( psz_enc );}/** * Converts "&lt;", "&gt;" and "&amp;" to "<", ">" and "&" * \param string to convert */void resolve_xml_special_chars( char *psz_value ){    char *p_pos = psz_value;    while ( *psz_value )    {        if( *psz_value == '&' )        {#define TRY_CHAR( src, len, dst )                   \            if( !strncmp( psz_value, src, len ) )   \            {                                       \                *p_pos = dst;                       \                psz_value += len;                   \            }#define TRY_LONGCHAR( src, len, dst )                   \            if( !strncmp( psz_value, src, len ) )       \            {                                           \                strncpy( p_pos, dst, strlen( dst ) );   \                p_pos += strlen( dst ) - 1;             \                psz_value += len;                       \            }            TRY_CHAR( "&lt;", 4, '<' )            else TRY_CHAR( "&gt;", 4, '>' )            else TRY_CHAR( "&amp;", 5, '&' )            else TRY_CHAR( "&quot;", 6, '"' )            else TRY_CHAR( "&apos;", 6, '\'' )            else if( psz_value[1] == '#' )            {                char *psz_end;                int i = strtol( psz_value+2, &psz_end, 10 );                if( *psz_end == ';' )                {                    if( i >= 32 && i <= 126 )                    {                        *p_pos = (char)i;                        psz_value = psz_end+1;                    }                    else                    {                        /* Unhandled code, FIXME */                        *p_pos = *psz_value;                        psz_value++;                    }                }                else                {                    /* Invalid entity number */                    *p_pos = *psz_value;                    psz_value++;                }            }            else TRY_LONGCHAR( "&Agrave;", 8, "À" )            else TRY_LONGCHAR( "&Aacute;", 8, "Á" )            else TRY_LONGCHAR( "&Acirc;", 7, "Â" )            else TRY_LONGCHAR( "&Atilde;", 8, "Ã" )            else TRY_LONGCHAR( "&Auml;", 6, "Ä" )            else TRY_LONGCHAR( "&Aring;", 7, "Å" )            else TRY_LONGCHAR( "&AElig;", 7, "Æ" )            else TRY_LONGCHAR( "&Ccedil;", 8, "Ç" )            else TRY_LONGCHAR( "&Egrave;", 8, "È" )            else TRY_LONGCHAR( "&Eacute;", 8, "É" )            else TRY_LONGCHAR( "&Ecirc;", 7, "Ê" )            else TRY_LONGCHAR( "&Euml;", 6, "Ë" )            else TRY_LONGCHAR( "&Igrave;", 8, "Ì" )            else TRY_LONGCHAR( "&Iacute;", 8, "Í" )            else TRY_LONGCHAR( "&Icirc;", 7, "Î" )            else TRY_LONGCHAR( "&Iuml;", 6, "Ï" )            else TRY_LONGCHAR( "&ETH;", 5, "Ð" )            else TRY_LONGCHAR( "&Ntilde;", 8, "Ñ" )            else TRY_LONGCHAR( "&Ograve;", 8, "Ò" )            else TRY_LONGCHAR( "&Oacute;", 8, "Ó" )            else TRY_LONGCHAR( "&Ocirc;", 7, "Ô" )            else TRY_LONGCHAR( "&Otilde;", 8, "Õ" )            else TRY_LONGCHAR( "&Ouml;", 6, "Ö" )            else TRY_LONGCHAR( "&Oslash;", 8, "Ø" )            else TRY_LONGCHAR( "&Ugrave;", 8, "Ù" )            else TRY_LONGCHAR( "&Uacute;", 8, "Ú" )            else TRY_LONGCHAR( "&Ucirc;", 7, "Û" )            else TRY_LONGCHAR( "&Uuml;", 6, "Ü" )            else TRY_LONGCHAR( "&Yacute;", 8, "Ý" )            else TRY_LONGCHAR( "&THORN;", 7, "Þ" )            else TRY_LONGCHAR( "&szlig;", 7, "ß" )            else TRY_LONGCHAR( "&agrave;", 8, "à" )            else TRY_LONGCHAR( "&aacute;", 8, "á" )            else TRY_LONGCHAR( "&acirc;", 7, "â" )            else TRY_LONGCHAR( "&atilde;", 8, "ã" )            else TRY_LONGCHAR( "&auml;", 6, "ä" )            else TRY_LONGCHAR( "&aring;", 7, "å" )            else TRY_LONGCHAR( "&aelig;", 7, "æ" )            else TRY_LONGCHAR( "&ccedil;", 8, "ç" )            else TRY_LONGCHAR( "&egrave;", 8, "è" )            else TRY_LONGCHAR( "&eacute;", 8, "é" )            else TRY_LONGCHAR( "&ecirc;", 7, "ê" )            else TRY_LONGCHAR( "&euml;", 6, "ë" )            else TRY_LONGCHAR( "&igrave;", 8, "ì" )            else TRY_LONGCHAR( "&iacute;", 8, "í" )            else TRY_LONGCHAR( "&icirc;", 7, "î" )            else TRY_LONGCHAR( "&iuml;", 6, "ï" )            else TRY_LONGCHAR( "&eth;", 5, "ð" )            else TRY_LONGCHAR( "&ntilde;", 8, "ñ" )            else TRY_LONGCHAR( "&ograve;", 8, "ò" )            else TRY_LONGCHAR( "&oacute;", 8, "ó" )            else TRY_LONGCHAR( "&ocirc;", 7, "ô" )            else TRY_LONGCHAR( "&otilde;", 8, "õ" )            else TRY_LONGCHAR( "&ouml;", 6, "ö" )            else TRY_LONGCHAR( "&oslash;", 8, "ø" )            else TRY_LONGCHAR( "&ugrave;", 8, "ù" )            else TRY_LONGCHAR( "&uacute;", 8, "ú" )            else TRY_LONGCHAR( "&ucirc;", 7, "û" )            else TRY_LONGCHAR( "&uuml;", 6, "ü" )            else TRY_LONGCHAR( "&yacute;", 8, "ý" )            else TRY_LONGCHAR( "&thorn;", 7, "þ" )            else TRY_LONGCHAR( "&yuml;", 6, "ÿ" )            else TRY_LONGCHAR( "&iexcl;", 7, "¡" )            else TRY_LONGCHAR( "&curren;", 8, "¤" )            else TRY_LONGCHAR( "&cent;", 6, "¢" )            else TRY_LONGCHAR( "&pound;", 7, "£" )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -