strings: add an input_item_t arg to vlc_strfinput()
[vlc.git] / include / vlc_strings.h
blob3f0c169e68646b732c07a355b3a19b560c8fa657
1 /*****************************************************************************
2 * vlc_strings.h: String functions
3 *****************************************************************************
4 * Copyright (C) 2006 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Antoine Cellerier <dionoea at videolan dot org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #ifndef VLC_STRINGS_H
25 #define VLC_STRINGS_H 1
27 /**
28 * \defgroup strings String helpers
29 * \ingroup cext
30 * @{
31 * \file
32 * Helper functions for nul-terminated strings
35 static inline int vlc_ascii_toupper( int c )
37 if ( c >= 'a' && c <= 'z' )
38 return c + ( 'A' - 'a' );
39 else
40 return c;
43 static inline int vlc_ascii_tolower( int c )
45 if ( c >= 'A' && c <= 'Z' )
46 return c + ( 'a' - 'A' );
47 else
48 return c;
51 /**
52 * Compare two ASCII strings ignoring case.
54 * The result is independent of the locale. If there are non-ASCII
55 * characters in the strings, their cases are NOT ignored in the
56 * comparison.
58 static inline int vlc_ascii_strcasecmp( const char *psz1, const char *psz2 )
60 const char *s1 = psz1;
61 const char *s2 = psz2;
62 int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
63 while ( *s1 && d == 0)
65 s1++;
66 s2++;
67 d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
70 return d;
73 static inline int vlc_ascii_strncasecmp( const char *psz1, const char *psz2, size_t n )
75 const char *s1 = psz1;
76 const char *s2 = psz2;
77 const char *s1end = psz1 + n;
78 int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
79 while ( *s1 && s1 < s1end && d == 0)
81 s1++;
82 s2++;
83 d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
86 if (s1 == s1end)
87 return 0;
88 else
89 return d;
92 /**
93 * Decodes XML entities.
95 * Decodes a null-terminated UTF-8 string of XML character data into a regular
96 * nul-terminated UTF-8 string. In other words, replaces XML entities and
97 * numerical character references with the corresponding characters.
99 * This function operates in place (the output is always of smaller or equal
100 * length than the input) and always succeeds.
102 * \param str null-terminated string [IN/OUT]
104 VLC_API void vlc_xml_decode(char *st);
107 * Encodes XML entites.
109 * Substitutes unsafe characters in a null-terminated UTF-8 strings with an
110 * XML entity or numerical character reference.
112 * \param str null terminated UTF-8 string
113 * \return On success, a heap-allocated null-terminated string is returned.
114 * If the input string was not a valid UTF-8 sequence, NULL is returned and
115 * errno is set to EILSEQ.
116 * If there was not enough memory, NULL is returned and errno is to ENOMEM.
118 VLC_API char *vlc_xml_encode(const char *str) VLC_MALLOC;
120 VLC_API char * vlc_b64_encode_binary( const uint8_t *, size_t );
121 VLC_API char * vlc_b64_encode( const char * );
123 VLC_API size_t vlc_b64_decode_binary_to_buffer( uint8_t *p_dst, size_t i_dst_max, const char *psz_src );
124 VLC_API size_t vlc_b64_decode_binary( uint8_t **pp_dst, const char *psz_src );
125 VLC_API char * vlc_b64_decode( const char *psz_src );
128 * Convenience wrapper for strftime().
130 * Formats the current time into a heap-allocated string.
132 * @param tformat time format (as with C strftime())
133 * @return an allocated string (must be free()'d), or NULL on memory error.
135 VLC_API char *vlc_strftime( const char * );
138 * Formats input meta-data.
140 * Formats input and input item meta-informations into a heap-allocated string.
142 VLC_API char *vlc_strfinput( input_thread_t *, input_item_t *, const char * );
144 static inline char *str_format( input_thread_t *input, input_item_t *item,
145 const char *fmt )
147 char *s1 = vlc_strftime( fmt );
148 char *s2 = vlc_strfinput( input, item, s1 );
149 free( s1 );
150 return s2;
153 VLC_API int vlc_filenamecmp(const char *, const char *);
155 void filename_sanitize(char *);
158 * @}
161 #endif