/src/vlc/include/vlc_charset.h
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * vlc_charset.h: Unicode UTF-8 wrappers function |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2003-2005 VLC authors and VideoLAN |
5 | | * Copyright © 2005-2010 Rémi Denis-Courmont |
6 | | * |
7 | | * Author: Rémi Denis-Courmont |
8 | | * |
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. |
13 | | * |
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. |
18 | | * |
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 | | *****************************************************************************/ |
23 | | |
24 | | #ifndef VLC_CHARSET_H |
25 | | #define VLC_CHARSET_H 1 |
26 | | |
27 | | /** |
28 | | * \file vlc_charset.h |
29 | | * \ingroup charset |
30 | | * \defgroup charset Character sets |
31 | | * \ingroup strings |
32 | | * @{ |
33 | | */ |
34 | | |
35 | | /** |
36 | | * Decodes a code point from UTF-8. |
37 | | * |
38 | | * Converts the first character in a UTF-8 sequence into a Unicode code point. |
39 | | * |
40 | | * \param str an UTF-8 bytes sequence [IN] |
41 | | * \param pwc address of a location to store the code point [OUT] |
42 | | * |
43 | | * \return the number of bytes occupied by the decoded code point |
44 | | * |
45 | | * \retval -1 not a valid UTF-8 sequence |
46 | | * \retval 0 null character (i.e. str points to an empty string) |
47 | | * \retval 1 (non-null) ASCII character |
48 | | * \retval 2-4 non-ASCII character |
49 | | */ |
50 | | VLC_API ssize_t vlc_towc(const char *str, uint32_t *restrict pwc); |
51 | | |
52 | | /** |
53 | | * Checks UTF-8 validity. |
54 | | * |
55 | | * Checks whether a null-terminated string is a valid UTF-8 bytes sequence. |
56 | | * |
57 | | * \param str string to check |
58 | | * |
59 | | * \retval str the string is a valid null-terminated UTF-8 sequence |
60 | | * \retval NULL the string is not an UTF-8 sequence |
61 | | */ |
62 | | VLC_USED static inline const char *IsUTF8(const char *str) |
63 | 26.5k | { |
64 | 26.5k | ssize_t n; |
65 | 26.5k | uint32_t cp; |
66 | | |
67 | 1.21M | while ((n = vlc_towc(str, &cp)) != 0) |
68 | 1.18M | if (likely(n != -1)) |
69 | 1.18M | str += n; |
70 | 1.86k | else |
71 | 1.86k | return NULL; |
72 | 24.6k | return str; |
73 | 26.5k | } Unexecuted instantiation: libasf.c:IsUTF8 Unexecuted instantiation: avi.c:IsUTF8 Unexecuted instantiation: es.c:IsUTF8 Unexecuted instantiation: flac.c:IsUTF8 Unexecuted instantiation: xiph_metadata.c:IsUTF8 Unexecuted instantiation: mp4.c:IsUTF8 Line | Count | Source | 63 | 15.3k | { | 64 | 15.3k | ssize_t n; | 65 | 15.3k | uint32_t cp; | 66 | | | 67 | 354k | while ((n = vlc_towc(str, &cp)) != 0) | 68 | 339k | if (likely(n != -1)) | 69 | 339k | str += n; | 70 | 0 | else | 71 | 0 | return NULL; | 72 | 15.3k | return str; | 73 | 15.3k | } |
Unexecuted instantiation: sap.c:IsUTF8 Unexecuted instantiation: smf.c:IsUTF8 Unexecuted instantiation: subtitle.c:IsUTF8 Unexecuted instantiation: ttml.c:IsUTF8 Unexecuted instantiation: substtml.c:IsUTF8 Unexecuted instantiation: webvtt.c:IsUTF8 Unexecuted instantiation: encvtt.c:IsUTF8 Unexecuted instantiation: subsvtt.c:IsUTF8 Unexecuted instantiation: libwebvtt_plugin_la-CSSLexer.c:IsUTF8 Unexecuted instantiation: ogg.c:IsUTF8 Unexecuted instantiation: cc.c:IsUTF8 Unexecuted instantiation: atsc_a65.c:IsUTF8 Unexecuted instantiation: stl.c:IsUTF8 Line | Count | Source | 63 | 11.1k | { | 64 | 11.1k | ssize_t n; | 65 | 11.1k | uint32_t cp; | 66 | | | 67 | 859k | while ((n = vlc_towc(str, &cp)) != 0) | 68 | 850k | if (likely(n != -1)) | 69 | 848k | str += n; | 70 | 1.86k | else | 71 | 1.86k | return NULL; | 72 | 9.31k | return str; | 73 | 11.1k | } |
Unexecuted instantiation: subsusf.c:IsUTF8 Unexecuted instantiation: substx3g.c:IsUTF8 Unexecuted instantiation: libvlc.c:IsUTF8 Unexecuted instantiation: chain.c:IsUTF8 Unexecuted instantiation: file.c:IsUTF8 Unexecuted instantiation: help.c:IsUTF8 Unexecuted instantiation: cmdline.c:IsUTF8 Unexecuted instantiation: libc.c:IsUTF8 Unexecuted instantiation: item.c:IsUTF8 Unexecuted instantiation: input.c:IsUTF8 Unexecuted instantiation: parse.c:IsUTF8 Unexecuted instantiation: replay_gain.c:IsUTF8 Unexecuted instantiation: stream.c:IsUTF8 Unexecuted instantiation: vout_intf.c:IsUTF8 Unexecuted instantiation: charset.c:IsUTF8 Unexecuted instantiation: strings.c:IsUTF8 Unexecuted instantiation: unicode.c:IsUTF8 Unexecuted instantiation: actions.c:IsUTF8 Unexecuted instantiation: messages.c:IsUTF8 Unexecuted instantiation: variables.c:IsUTF8 Unexecuted instantiation: vlmshell.c:IsUTF8 |
74 | | |
75 | | /** |
76 | | * Checks ASCII validity. |
77 | | * |
78 | | * Checks whether a null-terminated string is a valid ASCII bytes sequence |
79 | | * (non-printable ASCII characters 1-31 are permitted). |
80 | | * |
81 | | * \param str string to check |
82 | | * |
83 | | * \retval str the string is a valid null-terminated ASCII sequence |
84 | | * \retval NULL the string is not an ASCII sequence |
85 | | */ |
86 | | VLC_USED static inline const char *IsASCII(const char *str) |
87 | 0 | { |
88 | 0 | unsigned char c; |
89 | 0 |
|
90 | 0 | for (const char *p = str; (c = *p) != '\0'; p++) |
91 | 0 | if (c >= 0x80) |
92 | 0 | return NULL; |
93 | 0 | return str; |
94 | 0 | } Unexecuted instantiation: libasf.c:IsASCII Unexecuted instantiation: avi.c:IsASCII Unexecuted instantiation: es.c:IsASCII Unexecuted instantiation: flac.c:IsASCII Unexecuted instantiation: xiph_metadata.c:IsASCII Unexecuted instantiation: mp4.c:IsASCII Unexecuted instantiation: meta.c:IsASCII Unexecuted instantiation: sap.c:IsASCII Unexecuted instantiation: smf.c:IsASCII Unexecuted instantiation: subtitle.c:IsASCII Unexecuted instantiation: ttml.c:IsASCII Unexecuted instantiation: substtml.c:IsASCII Unexecuted instantiation: webvtt.c:IsASCII Unexecuted instantiation: encvtt.c:IsASCII Unexecuted instantiation: subsvtt.c:IsASCII Unexecuted instantiation: libwebvtt_plugin_la-CSSLexer.c:IsASCII Unexecuted instantiation: ogg.c:IsASCII Unexecuted instantiation: cc.c:IsASCII Unexecuted instantiation: atsc_a65.c:IsASCII Unexecuted instantiation: stl.c:IsASCII Unexecuted instantiation: subsdec.c:IsASCII Unexecuted instantiation: subsusf.c:IsASCII Unexecuted instantiation: substx3g.c:IsASCII Unexecuted instantiation: libvlc.c:IsASCII Unexecuted instantiation: chain.c:IsASCII Unexecuted instantiation: file.c:IsASCII Unexecuted instantiation: help.c:IsASCII Unexecuted instantiation: cmdline.c:IsASCII Unexecuted instantiation: libc.c:IsASCII Unexecuted instantiation: item.c:IsASCII Unexecuted instantiation: input.c:IsASCII Unexecuted instantiation: parse.c:IsASCII Unexecuted instantiation: replay_gain.c:IsASCII Unexecuted instantiation: stream.c:IsASCII Unexecuted instantiation: vout_intf.c:IsASCII Unexecuted instantiation: charset.c:IsASCII Unexecuted instantiation: strings.c:IsASCII Unexecuted instantiation: unicode.c:IsASCII Unexecuted instantiation: actions.c:IsASCII Unexecuted instantiation: messages.c:IsASCII Unexecuted instantiation: variables.c:IsASCII Unexecuted instantiation: vlmshell.c:IsASCII |
95 | | |
96 | | /** |
97 | | * Removes non-UTF-8 sequences. |
98 | | * |
99 | | * Replaces invalid or <i>over-long</i> UTF-8 bytes sequences within a |
100 | | * null-terminated string with question marks. This is so that the string can |
101 | | * be printed at least partially. |
102 | | * |
103 | | * \warning Do not use this were correctness is critical. use IsUTF8() and |
104 | | * handle the error case instead. This function is mainly for display or debug. |
105 | | * |
106 | | * \note Converting from Latin-1 to UTF-8 in place is not possible (the string |
107 | | * size would be increased). So it is not attempted even if it would otherwise |
108 | | * be less disruptive. |
109 | | * |
110 | | * \retval str the string is a valid null-terminated UTF-8 sequence |
111 | | * (i.e. no changes were made) |
112 | | * \retval NULL the string is not an UTF-8 sequence |
113 | | */ |
114 | | static inline char *EnsureUTF8(char *str) |
115 | 83.1k | { |
116 | 83.1k | char *ret = str; |
117 | 83.1k | ssize_t n; |
118 | 83.1k | uint32_t cp; |
119 | | |
120 | 526k | while ((n = vlc_towc(str, &cp)) != 0) |
121 | 443k | if (likely(n != -1)) |
122 | 442k | str += n; |
123 | 1.11k | else |
124 | 1.11k | { |
125 | 1.11k | *str++ = '?'; |
126 | 1.11k | ret = NULL; |
127 | 1.11k | } |
128 | 83.1k | return ret; |
129 | 83.1k | } Unexecuted instantiation: libasf.c:EnsureUTF8 Unexecuted instantiation: avi.c:EnsureUTF8 Unexecuted instantiation: es.c:EnsureUTF8 Unexecuted instantiation: flac.c:EnsureUTF8 xiph_metadata.c:EnsureUTF8 Line | Count | Source | 115 | 288 | { | 116 | 288 | char *ret = str; | 117 | 288 | ssize_t n; | 118 | 288 | uint32_t cp; | 119 | | | 120 | 3.45k | while ((n = vlc_towc(str, &cp)) != 0) | 121 | 3.16k | if (likely(n != -1)) | 122 | 3.16k | str += n; | 123 | 0 | else | 124 | 0 | { | 125 | 0 | *str++ = '?'; | 126 | 0 | ret = NULL; | 127 | 0 | } | 128 | 288 | return ret; | 129 | 288 | } |
Line | Count | Source | 115 | 303 | { | 116 | 303 | char *ret = str; | 117 | 303 | ssize_t n; | 118 | 303 | uint32_t cp; | 119 | | | 120 | 2.69k | while ((n = vlc_towc(str, &cp)) != 0) | 121 | 2.38k | if (likely(n != -1)) | 122 | 2.12k | str += n; | 123 | 264 | else | 124 | 264 | { | 125 | 264 | *str++ = '?'; | 126 | 264 | ret = NULL; | 127 | 264 | } | 128 | 303 | return ret; | 129 | 303 | } |
Line | Count | Source | 115 | 267 | { | 116 | 267 | char *ret = str; | 117 | 267 | ssize_t n; | 118 | 267 | uint32_t cp; | 119 | | | 120 | 2.19k | while ((n = vlc_towc(str, &cp)) != 0) | 121 | 1.92k | if (likely(n != -1)) | 122 | 1.07k | str += n; | 123 | 853 | else | 124 | 853 | { | 125 | 853 | *str++ = '?'; | 126 | 853 | ret = NULL; | 127 | 853 | } | 128 | 267 | return ret; | 129 | 267 | } |
Unexecuted instantiation: sap.c:EnsureUTF8 Unexecuted instantiation: smf.c:EnsureUTF8 Unexecuted instantiation: subtitle.c:EnsureUTF8 Unexecuted instantiation: ttml.c:EnsureUTF8 Unexecuted instantiation: substtml.c:EnsureUTF8 Unexecuted instantiation: webvtt.c:EnsureUTF8 Unexecuted instantiation: encvtt.c:EnsureUTF8 Unexecuted instantiation: subsvtt.c:EnsureUTF8 Unexecuted instantiation: libwebvtt_plugin_la-CSSLexer.c:EnsureUTF8 Unexecuted instantiation: ogg.c:EnsureUTF8 Line | Count | Source | 115 | 82.2k | { | 116 | 82.2k | char *ret = str; | 117 | 82.2k | ssize_t n; | 118 | 82.2k | uint32_t cp; | 119 | | | 120 | 518k | while ((n = vlc_towc(str, &cp)) != 0) | 121 | 436k | if (likely(n != -1)) | 122 | 436k | str += n; | 123 | 0 | else | 124 | 0 | { | 125 | 0 | *str++ = '?'; | 126 | 0 | ret = NULL; | 127 | 0 | } | 128 | 82.2k | return ret; | 129 | 82.2k | } |
Unexecuted instantiation: atsc_a65.c:EnsureUTF8 Unexecuted instantiation: stl.c:EnsureUTF8 Unexecuted instantiation: subsdec.c:EnsureUTF8 Unexecuted instantiation: subsusf.c:EnsureUTF8 Unexecuted instantiation: substx3g.c:EnsureUTF8 Unexecuted instantiation: libvlc.c:EnsureUTF8 Unexecuted instantiation: chain.c:EnsureUTF8 Unexecuted instantiation: file.c:EnsureUTF8 Unexecuted instantiation: help.c:EnsureUTF8 Unexecuted instantiation: cmdline.c:EnsureUTF8 Unexecuted instantiation: libc.c:EnsureUTF8 Unexecuted instantiation: item.c:EnsureUTF8 Unexecuted instantiation: input.c:EnsureUTF8 Unexecuted instantiation: parse.c:EnsureUTF8 Unexecuted instantiation: replay_gain.c:EnsureUTF8 Unexecuted instantiation: stream.c:EnsureUTF8 Unexecuted instantiation: vout_intf.c:EnsureUTF8 Unexecuted instantiation: charset.c:EnsureUTF8 Unexecuted instantiation: strings.c:EnsureUTF8 Unexecuted instantiation: unicode.c:EnsureUTF8 Unexecuted instantiation: actions.c:EnsureUTF8 Unexecuted instantiation: messages.c:EnsureUTF8 Unexecuted instantiation: variables.c:EnsureUTF8 Unexecuted instantiation: vlmshell.c:EnsureUTF8 |
130 | | |
131 | | /** |
132 | | * \defgroup iconv iconv wrappers |
133 | | * |
134 | | * (defined in src/extras/libc.c) |
135 | | * @{ |
136 | | */ |
137 | | |
138 | 3.85k | #define VLC_ICONV_ERR ((size_t) -1) |
139 | | typedef void *vlc_iconv_t; |
140 | | VLC_API vlc_iconv_t vlc_iconv_open( const char *, const char * ) VLC_USED; |
141 | | VLC_API size_t vlc_iconv( vlc_iconv_t, const char **, size_t *, char **, size_t * ) VLC_USED; |
142 | | VLC_API int vlc_iconv_close( vlc_iconv_t ); |
143 | | |
144 | | /** @} */ |
145 | | |
146 | | #include <stdarg.h> |
147 | | |
148 | | VLC_API int utf8_vfprintf( FILE *stream, const char *fmt, va_list ap ); |
149 | | VLC_API int utf8_fprintf( FILE *, const char *, ... ) VLC_FORMAT( 2, 3 ); |
150 | | VLC_API char * vlc_strcasestr(const char *, const char *) VLC_USED; |
151 | | |
152 | | VLC_API char * FromCharset( const char *charset, const void *data, size_t data_size ) VLC_USED; |
153 | | VLC_API void * ToCharset( const char *charset, const char *in, size_t *outsize ) VLC_USED; |
154 | | |
155 | | #ifdef __APPLE__ |
156 | | # include <CoreFoundation/CoreFoundation.h> |
157 | | |
158 | | /* Obtains a copy of the contents of a CFString in specified encoding. |
159 | | * Returns char* (must be freed by caller) or NULL on failure. |
160 | | */ |
161 | | VLC_USED static inline char *FromCFString(const CFStringRef cfString, |
162 | | const CFStringEncoding cfStringEncoding) |
163 | | { |
164 | | // Try the quick way to obtain the buffer |
165 | | const char *tmpBuffer = CFStringGetCStringPtr(cfString, cfStringEncoding); |
166 | | |
167 | | if (tmpBuffer != NULL) { |
168 | | return strdup(tmpBuffer); |
169 | | } |
170 | | |
171 | | // The quick way did not work, try the long way |
172 | | CFIndex length = CFStringGetLength(cfString); |
173 | | CFIndex maxSize = |
174 | | CFStringGetMaximumSizeForEncoding(length, cfStringEncoding); |
175 | | |
176 | | // If result would exceed LONG_MAX, kCFNotFound is returned |
177 | | if (unlikely(maxSize == kCFNotFound)) { |
178 | | return NULL; |
179 | | } |
180 | | |
181 | | // Account for the null terminator |
182 | | maxSize++; |
183 | | |
184 | | char *buffer = (char *)malloc(maxSize); |
185 | | |
186 | | if (unlikely(buffer == NULL)) { |
187 | | return NULL; |
188 | | } |
189 | | |
190 | | // Copy CFString in requested encoding to buffer |
191 | | Boolean success = CFStringGetCString(cfString, buffer, maxSize, cfStringEncoding); |
192 | | |
193 | | if (!success) |
194 | | FREENULL(buffer); |
195 | | return buffer; |
196 | | } |
197 | | #endif |
198 | | |
199 | | #ifdef _WIN32 |
200 | | # include <windows.h> |
201 | | |
202 | | VLC_USED |
203 | | static inline char *FromWide (const wchar_t *wide) |
204 | | { |
205 | | size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL); |
206 | | if (len == 0) |
207 | | return NULL; |
208 | | |
209 | | char *out = (char *)malloc (len); |
210 | | |
211 | | if (likely(out)) |
212 | | WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL); |
213 | | return out; |
214 | | } |
215 | | |
216 | | VLC_USED |
217 | | static inline wchar_t *ToWide (const char *utf8) |
218 | | { |
219 | | int len = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0); |
220 | | if (len == 0) |
221 | | return NULL; |
222 | | |
223 | | wchar_t *out = (wchar_t *)malloc (len * sizeof (wchar_t)); |
224 | | |
225 | | if (likely(out)) |
226 | | MultiByteToWideChar (CP_UTF8, 0, utf8, -1, out, len); |
227 | | return out; |
228 | | } |
229 | | |
230 | | VLC_USED VLC_MALLOC |
231 | | static inline char *ToCodePage (unsigned cp, const char *utf8) |
232 | | { |
233 | | wchar_t *wide = ToWide (utf8); |
234 | | if (wide == NULL) |
235 | | return NULL; |
236 | | |
237 | | size_t len = WideCharToMultiByte (cp, 0, wide, -1, NULL, 0, NULL, NULL); |
238 | | if (len == 0) { |
239 | | free(wide); |
240 | | return NULL; |
241 | | } |
242 | | |
243 | | char *out = (char *)malloc (len); |
244 | | if (likely(out != NULL)) |
245 | | WideCharToMultiByte (cp, 0, wide, -1, out, len, NULL, NULL); |
246 | | free (wide); |
247 | | return out; |
248 | | } |
249 | | |
250 | | VLC_USED VLC_MALLOC |
251 | | static inline char *FromCodePage (unsigned cp, const char *mb) |
252 | | { |
253 | | int len = MultiByteToWideChar (cp, 0, mb, -1, NULL, 0); |
254 | | if (len == 0) |
255 | | return NULL; |
256 | | |
257 | | wchar_t *wide = (wchar_t *)malloc (len * sizeof (wchar_t)); |
258 | | if (unlikely(wide == NULL)) |
259 | | return NULL; |
260 | | MultiByteToWideChar (cp, 0, mb, -1, wide, len); |
261 | | |
262 | | char *utf8 = FromWide (wide); |
263 | | free (wide); |
264 | | return utf8; |
265 | | } |
266 | | |
267 | | VLC_USED VLC_MALLOC |
268 | | static inline char *FromANSI (const char *ansi) |
269 | | { |
270 | | return FromCodePage (GetACP (), ansi); |
271 | | } |
272 | | |
273 | | VLC_USED VLC_MALLOC |
274 | | static inline char *ToANSI (const char *utf8) |
275 | | { |
276 | | return ToCodePage (GetACP (), utf8); |
277 | | } |
278 | | |
279 | | # define FromLocale FromANSI |
280 | | # define ToLocale ToANSI |
281 | | # define LocaleFree(s) free((char *)(s)) |
282 | | # define FromLocaleDup FromANSI |
283 | | # define ToLocaleDup ToANSI |
284 | | |
285 | | #elif defined(__OS2__) |
286 | | |
287 | | VLC_USED static inline char *FromLocale (const char *locale) |
288 | | { |
289 | | return locale ? FromCharset ((char *)"", locale, strlen(locale)) : NULL; |
290 | | } |
291 | | |
292 | | VLC_USED static inline char *ToLocale (const char *utf8) |
293 | | { |
294 | | size_t outsize; |
295 | | return utf8 ? (char *)ToCharset ("", utf8, &outsize) : NULL; |
296 | | } |
297 | | |
298 | | VLC_USED static inline void LocaleFree (const char *str) |
299 | | { |
300 | | free ((char *)str); |
301 | | } |
302 | | |
303 | | VLC_USED static inline char *FromLocaleDup (const char *locale) |
304 | | { |
305 | | return FromCharset ("", locale, strlen(locale)); |
306 | | } |
307 | | |
308 | | VLC_USED static inline char *ToLocaleDup (const char *utf8) |
309 | | { |
310 | | size_t outsize; |
311 | | return (char *)ToCharset ("", utf8, &outsize); |
312 | | } |
313 | | |
314 | | #else |
315 | | |
316 | | # define FromLocale(l) (l) |
317 | | # define ToLocale(u) (u) |
318 | | # define LocaleFree(s) ((void)(s)) |
319 | | # define FromLocaleDup strdup |
320 | | # define ToLocaleDup strdup |
321 | | #endif |
322 | | |
323 | | /** |
324 | | * Converts a nul-terminated string from ISO-8859-1 to UTF-8. |
325 | | */ |
326 | | static inline char *FromLatin1 (const char *latin) |
327 | 0 | { |
328 | 0 | char *str = (char *)malloc (2 * strlen (latin) + 1), *utf8 = str; |
329 | 0 | unsigned char c; |
330 | 0 |
|
331 | 0 | if (str == NULL) |
332 | 0 | return NULL; |
333 | 0 |
|
334 | 0 | while ((c = *(latin++)) != '\0') |
335 | 0 | { |
336 | 0 | if (c >= 0x80) |
337 | 0 | { |
338 | 0 | *(utf8++) = 0xC0 | (c >> 6); |
339 | 0 | *(utf8++) = 0x80 | (c & 0x3F); |
340 | 0 | } |
341 | 0 | else |
342 | 0 | *(utf8++) = c; |
343 | 0 | } |
344 | 0 | *(utf8++) = '\0'; |
345 | 0 |
|
346 | 0 | utf8 = (char *)realloc (str, utf8 - str); |
347 | 0 | return utf8 ? utf8 : str; |
348 | 0 | } Unexecuted instantiation: libasf.c:FromLatin1 Unexecuted instantiation: avi.c:FromLatin1 Unexecuted instantiation: es.c:FromLatin1 Unexecuted instantiation: flac.c:FromLatin1 Unexecuted instantiation: xiph_metadata.c:FromLatin1 Unexecuted instantiation: mp4.c:FromLatin1 Unexecuted instantiation: meta.c:FromLatin1 Unexecuted instantiation: sap.c:FromLatin1 Unexecuted instantiation: smf.c:FromLatin1 Unexecuted instantiation: subtitle.c:FromLatin1 Unexecuted instantiation: ttml.c:FromLatin1 Unexecuted instantiation: substtml.c:FromLatin1 Unexecuted instantiation: webvtt.c:FromLatin1 Unexecuted instantiation: encvtt.c:FromLatin1 Unexecuted instantiation: subsvtt.c:FromLatin1 Unexecuted instantiation: libwebvtt_plugin_la-CSSLexer.c:FromLatin1 Unexecuted instantiation: ogg.c:FromLatin1 Unexecuted instantiation: cc.c:FromLatin1 Unexecuted instantiation: atsc_a65.c:FromLatin1 Unexecuted instantiation: stl.c:FromLatin1 Unexecuted instantiation: subsdec.c:FromLatin1 Unexecuted instantiation: subsusf.c:FromLatin1 Unexecuted instantiation: substx3g.c:FromLatin1 Unexecuted instantiation: libvlc.c:FromLatin1 Unexecuted instantiation: chain.c:FromLatin1 Unexecuted instantiation: file.c:FromLatin1 Unexecuted instantiation: help.c:FromLatin1 Unexecuted instantiation: cmdline.c:FromLatin1 Unexecuted instantiation: libc.c:FromLatin1 Unexecuted instantiation: item.c:FromLatin1 Unexecuted instantiation: input.c:FromLatin1 Unexecuted instantiation: parse.c:FromLatin1 Unexecuted instantiation: replay_gain.c:FromLatin1 Unexecuted instantiation: stream.c:FromLatin1 Unexecuted instantiation: vout_intf.c:FromLatin1 Unexecuted instantiation: charset.c:FromLatin1 Unexecuted instantiation: strings.c:FromLatin1 Unexecuted instantiation: unicode.c:FromLatin1 Unexecuted instantiation: actions.c:FromLatin1 Unexecuted instantiation: messages.c:FromLatin1 Unexecuted instantiation: variables.c:FromLatin1 Unexecuted instantiation: vlmshell.c:FromLatin1 |
349 | | |
350 | | /** |
351 | | * \defgroup c_locale C/POSIX locale functions |
352 | | * @{ |
353 | | */ |
354 | | |
355 | | /** |
356 | | * Parses a double in C locale. |
357 | | * |
358 | | * This function parses a double-precision floating point number from a string |
359 | | * just like the standard strtod() but it uses the C locale. In other words, it |
360 | | * expects the POSIX/C/American decimal format regardless of the current |
361 | | * numeric locale. |
362 | | * |
363 | | * \param str nul-terminated string to parse |
364 | | * \param[out] end storage space for a pointer to the first unparsed byte |
365 | | * (or NULL to discard it) |
366 | | * \return the parsed double value (zero if no character could be parsed) |
367 | | */ |
368 | | VLC_API double vlc_strtod_c(const char *restrict str, char **restrict end) |
369 | | VLC_USED; |
370 | | |
371 | | /** |
372 | | * Parses a float in C locale. |
373 | | * |
374 | | * This function parses a single-precision floating point number from a string |
375 | | * just like the standard strtof() but it uses the C locale. In other words, it |
376 | | * expects the POSIX/C/American decimal format regardless of the current |
377 | | * numeric locale. |
378 | | * |
379 | | * \param str nul-terminated string to parse |
380 | | * \param[out] end storage space for a pointer to the first unparsed byte |
381 | | * (or NULL to discard it) |
382 | | * \return the parsed double value (zero if no character could be parsed) |
383 | | */ |
384 | | VLC_API float vlc_strtof_c(const char *restrict str, char **restrict end) |
385 | | VLC_USED; |
386 | | |
387 | | /** |
388 | | * Parses a double in C locale. |
389 | | * |
390 | | * This function parses a double-precision floating point number from a string |
391 | | * just like the standard atof() but it uses the C locale. In other words, it |
392 | | * expects the POSIX/C/American decimal format regardless of the current |
393 | | * numeric locale. |
394 | | * |
395 | | * \param str nul-terminated string to parse |
396 | | * \return the parsed double value (zero if no character could be parsed) |
397 | | */ |
398 | | VLC_USED static inline double vlc_atof_c(const char *str) |
399 | 0 | { |
400 | 0 | return vlc_strtod_c(str, NULL); |
401 | 0 | } Unexecuted instantiation: libasf.c:vlc_atof_c Unexecuted instantiation: avi.c:vlc_atof_c Unexecuted instantiation: es.c:vlc_atof_c Unexecuted instantiation: flac.c:vlc_atof_c Unexecuted instantiation: xiph_metadata.c:vlc_atof_c Unexecuted instantiation: mp4.c:vlc_atof_c Unexecuted instantiation: meta.c:vlc_atof_c Unexecuted instantiation: sap.c:vlc_atof_c Unexecuted instantiation: smf.c:vlc_atof_c Unexecuted instantiation: subtitle.c:vlc_atof_c Unexecuted instantiation: ttml.c:vlc_atof_c Unexecuted instantiation: substtml.c:vlc_atof_c Unexecuted instantiation: webvtt.c:vlc_atof_c Unexecuted instantiation: encvtt.c:vlc_atof_c Unexecuted instantiation: subsvtt.c:vlc_atof_c Unexecuted instantiation: libwebvtt_plugin_la-CSSLexer.c:vlc_atof_c Unexecuted instantiation: ogg.c:vlc_atof_c Unexecuted instantiation: cc.c:vlc_atof_c Unexecuted instantiation: atsc_a65.c:vlc_atof_c Unexecuted instantiation: stl.c:vlc_atof_c Unexecuted instantiation: subsdec.c:vlc_atof_c Unexecuted instantiation: subsusf.c:vlc_atof_c Unexecuted instantiation: substx3g.c:vlc_atof_c Unexecuted instantiation: libvlc.c:vlc_atof_c Unexecuted instantiation: chain.c:vlc_atof_c Unexecuted instantiation: file.c:vlc_atof_c Unexecuted instantiation: help.c:vlc_atof_c Unexecuted instantiation: cmdline.c:vlc_atof_c Unexecuted instantiation: libc.c:vlc_atof_c Unexecuted instantiation: item.c:vlc_atof_c Unexecuted instantiation: input.c:vlc_atof_c Unexecuted instantiation: parse.c:vlc_atof_c Unexecuted instantiation: replay_gain.c:vlc_atof_c Unexecuted instantiation: stream.c:vlc_atof_c Unexecuted instantiation: vout_intf.c:vlc_atof_c Unexecuted instantiation: charset.c:vlc_atof_c Unexecuted instantiation: strings.c:vlc_atof_c Unexecuted instantiation: unicode.c:vlc_atof_c Unexecuted instantiation: actions.c:vlc_atof_c Unexecuted instantiation: messages.c:vlc_atof_c Unexecuted instantiation: variables.c:vlc_atof_c Unexecuted instantiation: vlmshell.c:vlc_atof_c |
402 | | |
403 | | /** |
404 | | * Formats a string using the C locale. |
405 | | * |
406 | | * This function formats a string from a format string and a variable argument |
407 | | * list, just like the standard vasprintf() but using the C locale for the |
408 | | * formatting of numerals. |
409 | | * |
410 | | * \param[out] p storage space for a pointer to the heap-allocated formatted |
411 | | * string (undefined on error) |
412 | | * \param fmt format string |
413 | | * \param ap variable argument list |
414 | | * \return number of bytes formatted (excluding the nul terminator) |
415 | | * or -1 on error |
416 | | */ |
417 | | VLC_API int vlc_vasprintf_c(char **restrict p, const char *restrict fmt, |
418 | | va_list ap) VLC_USED; |
419 | | |
420 | | /** |
421 | | * Formats a string using the C locale. |
422 | | * |
423 | | * This function formats a string from a format string and a variable argument |
424 | | * list, just like the standard asprintf() but using the C locale for the |
425 | | * formatting of numerals. |
426 | | * |
427 | | * \param[out] p storage space for a pointer to the heap-allocated formatted |
428 | | * string (undefined on error) |
429 | | * \param fmt format string |
430 | | * \return number of bytes formatted (excluding the nul terminator) |
431 | | * or -1 on error |
432 | | */ |
433 | | VLC_API int vlc_asprintf_c( char **p, const char *fmt, ... ) VLC_USED; |
434 | | |
435 | | /** |
436 | | * Write a string to the output using the C locale |
437 | | * |
438 | | * This function formats a string from a format string and a variable argument |
439 | | * list, just like the standard vfprintf() but using the C locale for the |
440 | | * formatting of numerals. |
441 | | * |
442 | | * \param f output stream to write the string to |
443 | | * \param fmt format string |
444 | | * \param ap variable argument list |
445 | | * \return number of bytes formatted (excluding the nul terminator) |
446 | | * or -1 on error |
447 | | */ |
448 | | VLC_API int vlc_vfprintf_c(FILE *f, const char *fmt, va_list ap); |
449 | | |
450 | | /** |
451 | | * Write a string to the output using the C locale |
452 | | * |
453 | | * This function formats a string from a format string and a variable argument |
454 | | * list, just like the standard fprintf() but using the C locale for the |
455 | | * formatting of numerals. |
456 | | * |
457 | | * \param f output stream to write the string to |
458 | | * \param fmt format string |
459 | | * \return number of bytes formatted (excluding the nul terminator) |
460 | | * or -1 on error |
461 | | */ |
462 | | VLC_API int vlc_fprintf_c(FILE *f, const char *fmt, ...); |
463 | | |
464 | | int vlc_vsscanf_c(const char *, const char *, va_list) VLC_USED; |
465 | | int vlc_sscanf_c(const char*, const char*, ...) VLC_USED |
466 | | #ifdef __GNUC__ |
467 | | __attribute__((format(scanf, 2, 3))) |
468 | | #endif |
469 | | ; |
470 | | |
471 | | /** @} */ |
472 | | /** @} */ |
473 | | |
474 | | #endif |