/src/vlc/include/vlc_strings.h
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * vlc_strings.h: String functions |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2006 VLC authors and VideoLAN |
5 | | * |
6 | | * Authors: Antoine Cellerier <dionoea at videolan dot org> |
7 | | * |
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. |
12 | | * |
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. |
17 | | * |
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 | | *****************************************************************************/ |
22 | | |
23 | | #ifndef VLC_STRINGS_H |
24 | | #define VLC_STRINGS_H 1 |
25 | | |
26 | | /** |
27 | | * \defgroup strings String helpers |
28 | | * \ingroup cext |
29 | | * @{ |
30 | | * \file |
31 | | * Helper functions for nul-terminated strings |
32 | | */ |
33 | | |
34 | | typedef struct vlc_player_t vlc_player_t; |
35 | | |
36 | | static inline int vlc_ascii_toupper( int c ) |
37 | 0 | { |
38 | 0 | if ( c >= 'a' && c <= 'z' ) |
39 | 0 | return c + ( 'A' - 'a' ); |
40 | 0 | else |
41 | 0 | return c; |
42 | 0 | } Unexecuted instantiation: item.c:vlc_ascii_toupper Unexecuted instantiation: demux.c:vlc_ascii_toupper Unexecuted instantiation: input.c:vlc_ascii_toupper Unexecuted instantiation: vout_intf.c:vlc_ascii_toupper Unexecuted instantiation: strings.c:vlc_ascii_toupper Unexecuted instantiation: httpcookies.c:vlc_ascii_toupper Unexecuted instantiation: art.c:vlc_ascii_toupper Unexecuted instantiation: snapshot.c:vlc_ascii_toupper |
43 | | |
44 | | static inline int vlc_ascii_tolower( int c ) |
45 | 0 | { |
46 | 0 | if ( c >= 'A' && c <= 'Z' ) |
47 | 0 | return c + ( 'a' - 'A' ); |
48 | 0 | else |
49 | 0 | return c; |
50 | 0 | } Unexecuted instantiation: item.c:vlc_ascii_tolower Unexecuted instantiation: demux.c:vlc_ascii_tolower Unexecuted instantiation: input.c:vlc_ascii_tolower Unexecuted instantiation: vout_intf.c:vlc_ascii_tolower Unexecuted instantiation: strings.c:vlc_ascii_tolower Unexecuted instantiation: httpcookies.c:vlc_ascii_tolower Unexecuted instantiation: art.c:vlc_ascii_tolower Unexecuted instantiation: snapshot.c:vlc_ascii_tolower |
51 | | |
52 | | /** |
53 | | * Compare two ASCII strings ignoring case. |
54 | | * |
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. |
58 | | */ |
59 | | static inline int vlc_ascii_strcasecmp( const char *psz1, const char *psz2 ) |
60 | 0 | { |
61 | 0 | const char *s1 = psz1; |
62 | 0 | const char *s2 = psz2; |
63 | 0 | int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 ); |
64 | 0 | while ( *s1 && d == 0) |
65 | 0 | { |
66 | 0 | s1++; |
67 | 0 | s2++; |
68 | 0 | d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 ); |
69 | 0 | } |
70 | |
|
71 | 0 | return d; |
72 | 0 | } Unexecuted instantiation: item.c:vlc_ascii_strcasecmp Unexecuted instantiation: demux.c:vlc_ascii_strcasecmp Unexecuted instantiation: input.c:vlc_ascii_strcasecmp Unexecuted instantiation: vout_intf.c:vlc_ascii_strcasecmp Unexecuted instantiation: strings.c:vlc_ascii_strcasecmp Unexecuted instantiation: httpcookies.c:vlc_ascii_strcasecmp Unexecuted instantiation: art.c:vlc_ascii_strcasecmp Unexecuted instantiation: snapshot.c:vlc_ascii_strcasecmp |
73 | | |
74 | | static inline int vlc_ascii_strncasecmp( const char *psz1, const char *psz2, size_t n ) |
75 | 0 | { |
76 | 0 | const char *s1 = psz1; |
77 | 0 | const char *s2 = psz2; |
78 | 0 | const char *s1end = psz1 + n; |
79 | 0 | int d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 ); |
80 | 0 | while ( *s1 && s1 < s1end && d == 0) |
81 | 0 | { |
82 | 0 | s1++; |
83 | 0 | s2++; |
84 | 0 | d = vlc_ascii_tolower( *s1 ) - vlc_ascii_tolower( *s2 ); |
85 | 0 | } |
86 | |
|
87 | 0 | if (s1 == s1end) |
88 | 0 | return 0; |
89 | 0 | else |
90 | 0 | return d; |
91 | 0 | } Unexecuted instantiation: item.c:vlc_ascii_strncasecmp Unexecuted instantiation: demux.c:vlc_ascii_strncasecmp Unexecuted instantiation: input.c:vlc_ascii_strncasecmp Unexecuted instantiation: vout_intf.c:vlc_ascii_strncasecmp Unexecuted instantiation: strings.c:vlc_ascii_strncasecmp Unexecuted instantiation: httpcookies.c:vlc_ascii_strncasecmp Unexecuted instantiation: art.c:vlc_ascii_strncasecmp Unexecuted instantiation: snapshot.c:vlc_ascii_strncasecmp |
92 | | |
93 | | /** |
94 | | * Decodes XML entities. |
95 | | * |
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. |
99 | | * |
100 | | * This function operates in place (the output is always of smaller or equal |
101 | | * length than the input) and always succeeds. |
102 | | * |
103 | | * \param str null-terminated string [IN/OUT] |
104 | | */ |
105 | | VLC_API void vlc_xml_decode(char *st); |
106 | | |
107 | | /** |
108 | | * Encodes XML entities. |
109 | | * |
110 | | * Substitutes unsafe characters in a null-terminated UTF-8 strings with an |
111 | | * XML entity or numerical character reference. |
112 | | * |
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. |
118 | | */ |
119 | | VLC_API char *vlc_xml_encode(const char *str) VLC_MALLOC; |
120 | | |
121 | | /** |
122 | | * Encode binary data as hex string |
123 | | * |
124 | | * Writes a given data buffer to the output buffer as a null terminated |
125 | | * string in hexadecimal representation. |
126 | | * |
127 | | * \param input Input buffer |
128 | | * \param size Input buffer size |
129 | | * \param[out] output Output buffer to write the string to |
130 | | */ |
131 | | VLC_API void vlc_hex_encode_binary(const void *input, size_t size, char *output); |
132 | | |
133 | | /** |
134 | | * Base64 encoding. |
135 | | * |
136 | | * Encodes a buffer into base64 as a (nul-terminated) string. |
137 | | * |
138 | | * \param base start address of buffer to encode |
139 | | * \param length length in bytes of buffer to encode |
140 | | * \return a heap-allocated nul-terminated string |
141 | | * (or NULL on allocation error). |
142 | | */ |
143 | | VLC_API char *vlc_b64_encode_binary(const void *base, size_t length) |
144 | | VLC_USED VLC_MALLOC; |
145 | | |
146 | | /** |
147 | | * Base64 encoding (string). |
148 | | * |
149 | | * Encodes a nul-terminated string into Base64. |
150 | | * |
151 | | * \param str nul-terminated string to encode |
152 | | * \return a heap-allocated nul-terminated string |
153 | | * (or NULL on allocation error). |
154 | | */ |
155 | | VLC_API char *vlc_b64_encode(const char *str) VLC_USED VLC_MALLOC; |
156 | | |
157 | | VLC_API size_t vlc_b64_decode_binary_to_buffer(void *p_dst, size_t i_dst_max, const char *psz_src ); |
158 | | VLC_API size_t vlc_b64_decode_binary( uint8_t **pp_dst, const char *psz_src ); |
159 | | VLC_API char * vlc_b64_decode( const char *psz_src ); |
160 | | |
161 | | /** |
162 | | * Convenience wrapper for strftime(). |
163 | | * |
164 | | * Formats the current time into a heap-allocated string. |
165 | | * |
166 | | * \param tformat time format (as with C strftime()) |
167 | | * \return an allocated string (must be free()'d), or NULL on memory error. |
168 | | */ |
169 | | VLC_API char *vlc_strftime( const char * ); |
170 | | |
171 | | /** |
172 | | * Formats input meta-data. |
173 | | * |
174 | | * Formats input and input item meta-informations into a heap-allocated string |
175 | | * according to the given player format string. |
176 | | * |
177 | | * The player format string contains of replacement specifiers, each specifier begins |
178 | | * with the dollar character (`$`) followed by one of the following letters: |
179 | | * |
180 | | * Char | Replacement |
181 | | * ----- | ------------------------------- |
182 | | * `a` | Artist metadata |
183 | | * `b` | Album title metadata |
184 | | * `c` | Copyright information metadata |
185 | | * `d` | Description metadata |
186 | | * `e` | 'Encoded by' metadata |
187 | | * `f` | Displayed output frame (`-` if not available) |
188 | | * `g` | Genre metadata |
189 | | * `l` | Language metadata |
190 | | * `n` | Current Track number metadata |
191 | | * `o` | Total Track number metadata |
192 | | * `p` | Now playing metadata (i.e. currently playing title for livestreams) |
193 | | * `r` | Rating metadata |
194 | | * `s` | Selected subtitle language (`-` if not available) |
195 | | * `t` | Title metadata |
196 | | * `u` | URL metadata |
197 | | * `A` | Date metadata |
198 | | * `B` | Selected audio track bitrate (`-` if not available) |
199 | | * `C` | Current chapter index (`-` if not available) |
200 | | * `D` | Item duration (`--:--:--` if not available) |
201 | | * `F` | Item URI |
202 | | * `I` | Current title index (`-` if not available) |
203 | | * `L` | Item remaining time (`--:--:--` if not available) |
204 | | * `N` | Item name |
205 | | * `O` | Current audio track language (`-` if not available) |
206 | | * `P` | Current playback position (0.0 to 1.0, `--.-%` if not available) |
207 | | * `R` | Current playback speed (1.0 is normal speed, `-` if not available) |
208 | | * `S` | Current audio track samplerate (`-` if not available) |
209 | | * `T` | Current playback time (`--:--:--` if not available) |
210 | | * `U` | Publisher metadata |
211 | | * `V` | Volume (0 to 256, `---` if not available) |
212 | | * `Z` | Now playing or Artist/Title metadata depending what is available |
213 | | * `_` | Newline (`\n`) |
214 | | * |
215 | | * Additionally characters can be prepended with a whitespace (e.g. `$ T`), which will |
216 | | * cause a replacement with nothing, when not available, instead of the placeholders |
217 | | * documented above. |
218 | | * |
219 | | * \param player a locked player instance or NULL (player and item can't be |
220 | | * both NULL) |
221 | | * \param item a valid item or NULL (player and item can't be both NULL) |
222 | | * \param fmt format string |
223 | | * \return an allocated formatted string (must be free()'d), or NULL in case of error |
224 | | */ |
225 | | VLC_API char *vlc_strfplayer( vlc_player_t *player, input_item_t *item, |
226 | | const char *fmt ); |
227 | | |
228 | | static inline char *str_format( vlc_player_t *player, input_item_t *item, |
229 | | const char *fmt ) |
230 | 0 | { |
231 | 0 | char *s1 = vlc_strftime( fmt ); |
232 | 0 | char *s2 = vlc_strfplayer( player, item, s1 ); |
233 | 0 | free( s1 ); |
234 | 0 | return s2; |
235 | 0 | } Unexecuted instantiation: item.c:str_format Unexecuted instantiation: demux.c:str_format Unexecuted instantiation: input.c:str_format Unexecuted instantiation: vout_intf.c:str_format Unexecuted instantiation: strings.c:str_format Unexecuted instantiation: httpcookies.c:str_format Unexecuted instantiation: art.c:str_format Unexecuted instantiation: snapshot.c:str_format |
236 | | |
237 | | VLC_API int vlc_filenamecmp(const char *, const char *); |
238 | | |
239 | | void filename_sanitize(char *); |
240 | | |
241 | | /** |
242 | | * @} |
243 | | */ |
244 | | |
245 | | #endif |