qml: rename ExpandGridView.model to ExpandGridView.delegateModel
[vlc.git] / include / vlc_strings.h
blob411f4a8cebf367c7f864438d72e2a622b929986f
1 /*****************************************************************************
2 * vlc_strings.h: String functions
3 *****************************************************************************
4 * Copyright (C) 2006 VLC authors and VideoLAN
6 * Authors: Antoine Cellerier <dionoea at videolan dot org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifndef VLC_STRINGS_H
24 #define VLC_STRINGS_H 1
26 /**
27 * \defgroup strings String helpers
28 * \ingroup cext
29 * @{
30 * \file
31 * Helper functions for nul-terminated strings
34 typedef struct vlc_player_t vlc_player_t;
36 static inline int vlc_ascii_toupper( int c )
38 if ( c >= 'a' && c <= 'z' )
39 return c + ( 'A' - 'a' );
40 else
41 return c;
44 static inline int vlc_ascii_tolower( int c )
46 if ( c >= 'A' && c <= 'Z' )
47 return c + ( 'a' - 'A' );
48 else
49 return c;
52 /**
53 * Compare two ASCII strings ignoring case.
55 * The result is independent of the locale. If there are non-ASCII
56 * characters in the strings, their cases are NOT ignored in the
57 * comparison.
59 static inline int vlc_ascii_strcasecmp( const char *psz1, const char *psz2 )
61 const char *s1 = psz1;
62 const char *s2 = psz2;
63 int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
64 while ( *s1 && d == 0)
66 s1++;
67 s2++;
68 d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
71 return d;
74 static inline int vlc_ascii_strncasecmp( const char *psz1, const char *psz2, size_t n )
76 const char *s1 = psz1;
77 const char *s2 = psz2;
78 const char *s1end = psz1 + n;
79 int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
80 while ( *s1 && s1 < s1end && d == 0)
82 s1++;
83 s2++;
84 d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 );
87 if (s1 == s1end)
88 return 0;
89 else
90 return d;
93 /**
94 * Decodes XML entities.
96 * Decodes a null-terminated UTF-8 string of XML character data into a regular
97 * nul-terminated UTF-8 string. In other words, replaces XML entities and
98 * numerical character references with the corresponding characters.
100 * This function operates in place (the output is always of smaller or equal
101 * length than the input) and always succeeds.
103 * \param str null-terminated string [IN/OUT]
105 VLC_API void vlc_xml_decode(char *st);
108 * Encodes XML entites.
110 * Substitutes unsafe characters in a null-terminated UTF-8 strings with an
111 * XML entity or numerical character reference.
113 * \param str null terminated UTF-8 string
114 * \return On success, a heap-allocated null-terminated string is returned.
115 * If the input string was not a valid UTF-8 sequence, NULL is returned and
116 * errno is set to EILSEQ.
117 * If there was not enough memory, NULL is returned and errno is to ENOMEM.
119 VLC_API char *vlc_xml_encode(const char *str) VLC_MALLOC;
122 * Base64 encoding.
124 * Encodes a buffer into base64 as a (nul-terminated) string.
126 * \param base start address of buffer to encode
127 * \param length length in bytes of buffer to encode
128 * \return a heap-allocated nul-terminated string
129 * (or NULL on allocation error).
131 VLC_API char *vlc_b64_encode_binary(const void *base, size_t length)
132 VLC_USED VLC_MALLOC;
135 * Base64 encoding (string).
137 * Encodes a nul-terminated string into Base64.
139 * \param str nul-terminated string to encode
140 * \return a heap-allocated nul-terminated string
141 * (or NULL on allocation error).
143 VLC_API char *vlc_b64_encode(const char *str) VLC_USED VLC_MALLOC;
145 VLC_API size_t vlc_b64_decode_binary_to_buffer(void *p_dst, size_t i_dst_max, const char *psz_src );
146 VLC_API size_t vlc_b64_decode_binary( uint8_t **pp_dst, const char *psz_src );
147 VLC_API char * vlc_b64_decode( const char *psz_src );
150 * Convenience wrapper for strftime().
152 * Formats the current time into a heap-allocated string.
154 * @param tformat time format (as with C strftime())
155 * @return an allocated string (must be free()'d), or NULL on memory error.
157 VLC_API char *vlc_strftime( const char * );
160 * Formats input meta-data.
162 * Formats input and input item meta-informations into a heap-allocated string.
164 * @param player a locked player instance or NULL (player and item can't be
165 * both NULL)
166 * @param item a valid item or NULL (player and item can't be both NULL)
167 * @param fmt format string
168 * @return the formated string, or NULL in case of error, the string need to be
169 * freed with ()
171 VLC_API char *vlc_strfplayer( vlc_player_t *player, input_item_t *item,
172 const char *fmt );
174 static inline char *str_format( vlc_player_t *player, input_item_t *item,
175 const char *fmt )
177 char *s1 = vlc_strftime( fmt );
178 char *s2 = vlc_strfplayer( player, item, s1 );
179 free( s1 );
180 return s2;
183 VLC_API int vlc_filenamecmp(const char *, const char *);
185 void filename_sanitize(char *);
188 * @}
191 #endif