1 /*****************************************************************************
2 * strings.c: String related functions
3 *****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan dot org>
8 * Daniel Stranger <vlc at schmaller dot de>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
32 #include "vlc_strings.h"
35 * Decode URI encoded string
36 * \return decoded duplicated string
38 char *decode_encoded_URI_duplicate( const char *psz )
40 char *psz_dup = strdup( psz );
41 decode_encoded_URI( psz_dup );
46 * Decode URI encoded string
49 void decode_encoded_URI( char *psz )
51 char *dup = strdup( psz );
69 *psz++ = strtol( val, NULL, 16 );
86 * Converts "<", ">" and "&" to "<", ">" and "&"
87 * \param string to convert
89 void resolve_xml_special_chars( char *psz_value )
91 char *p_pos = psz_value;
95 if( !strncmp( psz_value, "<", 4 ) )
100 else if( !strncmp( psz_value, ">", 4 ) )
105 else if( !strncmp( psz_value, "&", 5 ) )
110 else if( !strncmp( psz_value, """, 6 ) )
115 else if( !strncmp( psz_value, "'", 6 ) )
133 * Converts '<', '>', '\"', '\'' and '&' to their html entities
134 * \param psz_content simple element content that is to be converted
136 char *convert_xml_special_chars( const char *psz_content )
138 char *psz_temp = malloc( 6 * strlen( psz_content ) + 1 );
139 const char *p_from = psz_content;
140 char *p_to = psz_temp;
144 if ( *p_from == '<' )
146 strcpy( p_to, "<" );
149 else if ( *p_from == '>' )
151 strcpy( p_to, ">" );
154 else if ( *p_from == '&' )
156 strcpy( p_to, "&" );
159 else if( *p_from == '\"' )
161 strcpy( p_to, """ );
164 else if( *p_from == '\'' )
166 strcpy( p_to, "'" );